Skip to main content

zip

python setup.py sdist build

upload

twine upload dist/*

upgrade

python -m pip install --upgrade lc_pytools

lc_pytools

linear_algebra

1、det

algorithm

1、dijkstra

how to use it

dijkstra(Map, n)
from heapq import *
n = 3
INF = float('inf')
Map = [
    [],
    [[2, 2], [3, 4]],
    [[3, 1]], 
    []
]

def dijkstra(Map, n) :
    dist = [INF for _ in range(n + 1)]
    mark = [0 for _ in range(n + 1)]
    heap = []
    dist[1] = 0
    heappush(heap, [dist[1], 1])
    while heap :
        d, t = heappop(heap)
        if mark[t] : continue
        mark[t] = 1
        if t == n : break
        # new
        for e, s in Map[t] :
            if mark[e] : continue
            if dist[e] > dist[t] + s :
                dist[e] = dist[t] + s
                heappush(heap, [dist[e], e])
    if dist[n] == INF : return -1
    else: return dist[n]
    
if __name__ == "__main__":
    res = dijkstra(Map, n)
    print(res)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lc_pytools-1.1.1.tar.gz (2.1 kB view details)

Uploaded Source

File details

Details for the file lc_pytools-1.1.1.tar.gz.

File metadata

  • Download URL: lc_pytools-1.1.1.tar.gz
  • Upload date:
  • Size: 2.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.12

File hashes

Hashes for lc_pytools-1.1.1.tar.gz
Algorithm Hash digest
SHA256 d3111487692dad5bd974b8e5eb74b1b1fa500f239f668353e28f08cb7650fa37
MD5 80e72fafe8cbfac3d80e0bd810d4d83f
BLAKE2b-256 ce93745183f15e2a9c83a232b42028140418d4d2825380fd7b296b15200d95f6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.1 This release

1 file

1.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page