結果
問題 | No.1254 補強への架け橋 |
ユーザー | mkawa2 |
提出日時 | 2021-10-29 14:57:04 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 669 ms / 2,000 ms |
コード長 | 1,571 bytes |
コンパイル時間 | 213 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 60,984 KB |
最終ジャッジ日時 | 2024-10-07 08:34:25 |
合計ジャッジ時間 | 24,320 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 123 |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (1, 0), (0, -1), (-1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 1 << 63 # md = 998244353 md = 10**9+7 def dfs(to, root=0): n = len(to) par = [-1]*n go = [True]*n stack = [root] loop = -1 while stack: u = stack.pop() if go[u]: go[u] = False stack.append(u) # toの変数注意 for v in to[u]: if v == par[u]: continue if not go[v]: return v, u, par stack.append(v) par[v] = u else: # toの変数注意 for v in to[u]: if v == par[u]: continue n = II() to = [[] for _ in range(n)] uvtoi = {} for i in range(n): u, v = LI1() to[u].append(v) to[v].append(u) uvtoi[u, v] = uvtoi[v, u] = i p, u, par = dfs(to, 0) uu = [p, u] while uu[-1] != p: v = par[uu[-1]] uu.append(v) ans = [] for u, v in zip(uu, uu[1:]): ans.append(uvtoi[u, v]+1) print(len(ans)) print(*ans)