Closed bqi343 closed 10 months ago
some of them just can't be solved with python though?
Well, for those that can.
Btw, ChatGPT does a good job of converting existing solutions into Python code, if we want to do that instead of writing solutions from scratch. For example,
https://usaco.guide/gold/shortest-paths?lang=py#implementation
->
import sys
INF = 1e18
def main():
n, m, q = map(int, input().strip().split())
mat = [[INF for j in range(n)] for i in range(n)]
for i in range(m):
u, v, w = map(int, input().strip().split())
u -= 1
v -= 1
if w < mat[u][v]:
mat[u][v] = mat[v][u] = w
# floyd-warshall
for k in range(n):
for i in range(n):
for j in range(i + 1, n):
if mat[i][k] + mat[k][j] < mat[i][j]:
mat[i][j] = mat[j][i] = mat[i][k] + mat[k][j]
for i in range(q):
u, v = map(int, input().strip().split())
u -= 1
v -= 1
if u == v:
mat[u][v] = 0
if mat[u][v] == INF:
mat[u][v] = -1
print(mat[u][v])
if __name__ == '__main__':
sys.exit(main())
(which TLEs but is correct)
Prompt:
Can you convert the following code to Python?
```cpp
(add code here ...)
i feel like there's enough python support to warrant closing this now
what're yall's opinions on this
feel free to close
Especially for Bronze and Silver (see https://usaco.guide/general/choosing-lang?lang=py#can-i-pass-every-problem-in-every-language for the note about 2022-23)