This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from atcoder.dsu import DSU | |
| N, M = map(int, input().split()) | |
| G = [[] for _ in range(N + 1)] | |
| for _ in range(M): | |
| u, v = map(int, input().split()) | |
| G[u].append(v) | |
| G[v].append(u) | |
| uf_small = DSU(N + 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def binary_search(vec, q): | |
| ok, ng = -1, len(vec) | |
| while ng - ok > 1: | |
| mid = (ng + ok) // 2 | |
| if vec[mid] > q: | |
| ng = mid | |
| else: | |
| ok = mid | |
| return ok |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from atcoder.dsu import DSU | |
| def solv(): | |
| C = 26 | |
| if S == T: # 2つの文字列を一致のとき変換の必要なし | |
| return 0 | |
| to = [-1] * C | |
| for i in range(N): | |
| sc = ord(S[i]) - ord("a") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pets = ['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'cat'] | |
| print(pets) | |
| while 'cat' in pets: | |
| pets.remove('cat') | |
| print(pets) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| sys.setrecursionlimit(10**9) | |
| def dfs(p, v): | |
| global ans | |
| cnt = 0 | |
| for u in T[v]: | |
| if u == p: # 親は無視 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| N, R, C = map(int, input().split()) | |
| S = list(input()) | |
| taka_r, taka_c = R, C | |
| ans = [] | |
| s = set() | |
| cur_r, cur_c = 0, 0 | |
| s.add((cur_r, cur_c)) | |
| for dir in S: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import heapq | |
| def dijkstra(node): # ダイクストラ法 | |
| dist = [float("inf")] * (2 * N) | |
| dist[node] = 0 | |
| que = [] | |
| heapq.heappush(que, (dist[node], node)) | |
| while que: | |
| node = heapq.heappop(que) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from atcoder.dsu import DSU | |
| N, M = map(int, input().split()) | |
| dsu = DSU(N) | |
| edge = [] | |
| for i in range(M): | |
| a, b = map(lambda x: int(x) - 1, input().split()) | |
| if dsu.same(a, b): # すでにサーバー同士は繋がっている。 | |
| edge.append((i, a, b)) # 繋ぎ変えに使用するケーブルを記録しておく | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def dfs(cur, dist): | |
| global ans | |
| if cur == N - 1: | |
| ans = min(ans, dist) | |
| return | |
| visit[cur] = True | |
| for nxt, w in G[cur]: | |
| if visit[nxt]: | |
| continue | |
| dfs(nxt, dist ^ w) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| N, W = map(int, input().split()) | |
| board = [[] for _ in range(W)] | |
| ans = [-1] * N # 何秒後まで残るか。-1なら最後まで消えない | |
| for i in range(1, N + 1): | |
| X, Y = map(int, input().split()) | |
| board[X - 1].append((Y - 1, i - 1)) | |
| min_cnt = 10**9 + 1 # 各列にあるブロック数の最小値 | |
| for i in range(W): | |
| board[i].sort() |