diff --git a/zeta_python/13505.py b/zeta_python/completed/13505.py similarity index 78% rename from zeta_python/13505.py rename to zeta_python/completed/13505.py index 29315d5..24a750a 100644 --- a/zeta_python/13505.py +++ b/zeta_python/completed/13505.py @@ -4,7 +4,7 @@ input = sys.stdin.readline def get_max_xor(N, S): - trie = [[0, 0] for _ in range(150000)] + trie = [[0, 0] for _ in range(3000000)] cnt = 0 for s in S: @@ -27,12 +27,16 @@ def get_max_xor(N, S): flag = False if trie[idx1][0] and trie[idx2][1]: - D.append((depth + 1, trie[idx1][0], trie[idx2][1], xor + 1 << (29 - depth))) + D.append( + (depth + 1, trie[idx1][0], trie[idx2][1], xor + (1 << (29 - depth))) + ) flag = True if trie[idx1][1] and trie[idx2][0]: - D.append((depth + 1, trie[idx1][1], trie[idx2][0], xor + 1 << (29 - depth))) + D.append( + (depth + 1, trie[idx1][1], trie[idx2][0], xor + (1 << (29 - depth))) + ) flag = True - print(D) + if flag: continue @@ -40,7 +44,6 @@ def get_max_xor(N, S): D.append((depth + 1, trie[idx1][0], trie[idx2][0], xor)) if trie[idx1][1] and trie[idx2][1]: D.append((depth + 1, trie[idx1][1], trie[idx2][1], xor)) - print(n) return max(n) diff --git a/zeta_python/completed/1865.py b/zeta_python/completed/1865.py new file mode 100644 index 0000000..03a1cb2 --- /dev/null +++ b/zeta_python/completed/1865.py @@ -0,0 +1,35 @@ +import sys + +input = sys.stdin.readline + +INF = 1 << 30 + + +def bellman_ford(N, E, start=1): + dist = [INF] * (N + 1) + parent = [0] * (N + 1) + + dist[start] = 0 + for _ in range(1, N + 1): + for u, v, w in E: + if dist[u] + w < dist[v]: + dist[v] = dist[u] + w + parent[v] = u + + for u, v, w in E: + if dist[u] + w < dist[v]: + return -INF + return dist[N] + + +if __name__ == "__main__": + T = int(input()) + for _ in range(T): + N, M, W = map(int, input().split()) + E = [] + for s, e, w in [map(int, input().split()) for _ in range(M)]: + E.append((s, e, w)) + E.append((e, s, w)) + for s, e, w in [map(int, input().split()) for _ in range(W)]: + E.append((s, e, -w)) + print("YES" if bellman_ford(N, E) < 0 else "NO")