結果
問題 | No.416 旅行会社 |
ユーザー | Tawara |
提出日時 | 2016-08-27 00:35:27 |
言語 | PyPy2 (7.3.15) |
結果 |
AC
|
実行時間 | 1,007 ms / 4,000 ms |
コード長 | 1,049 bytes |
コンパイル時間 | 1,731 ms |
コンパイル使用メモリ | 77,056 KB |
実行使用メモリ | 261,248 KB |
最終ジャッジ日時 | 2024-04-26 05:00:32 |
合計ジャッジ時間 | 13,378 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 427 ms
140,424 KB |
testcase_01 | AC | 84 ms
77,484 KB |
testcase_02 | AC | 83 ms
77,300 KB |
testcase_03 | AC | 84 ms
77,472 KB |
testcase_04 | AC | 83 ms
77,076 KB |
testcase_05 | AC | 86 ms
77,344 KB |
testcase_06 | AC | 86 ms
77,468 KB |
testcase_07 | AC | 100 ms
78,864 KB |
testcase_08 | AC | 163 ms
82,420 KB |
testcase_09 | AC | 226 ms
86,776 KB |
testcase_10 | AC | 437 ms
139,964 KB |
testcase_11 | AC | 604 ms
261,248 KB |
testcase_12 | AC | 552 ms
220,104 KB |
testcase_13 | AC | 529 ms
220,228 KB |
testcase_14 | AC | 876 ms
157,216 KB |
testcase_15 | AC | 936 ms
170,476 KB |
testcase_16 | AC | 951 ms
188,032 KB |
testcase_17 | AC | 1,007 ms
194,852 KB |
testcase_18 | AC | 968 ms
162,504 KB |
testcase_19 | AC | 873 ms
178,040 KB |
testcase_20 | AC | 763 ms
139,044 KB |
ソースコード
import sys from collections import deque def dfs(b,h,E,ans,reachable,turn): if reachable[h]: return reachable[h] = True ans[h] = turn for nxt in E[h]: if b == nxt: continue dfs(h,nxt,E,ans,reachable,turn) def solve(): sys.setrecursionlimit(200000) N,M,Q = map(int,raw_input().split()) reachable = [False]*N EL = [[] for i in xrange(N)] ans = [None]*N BEset = [set() for i in xrange(N)] BE = deque() Edge = [map(lambda x: int(x)-1,raw_input().split()) for i in xrange(M)] for i in xrange(Q): ft = map(lambda x: int(x)-1,raw_input().split()) BEset[ft[0]].add(ft[1]) BE.appendleft(ft) for f,t in Edge: if t in BEset[f] or f in BEset[t]: continue EL[f].append(t) EL[t].append(f) dfs(-1,0,EL,ans,reachable,-1) for i,(f,t) in enumerate(BE): EL[f].append(t) EL[t].append(f) if reachable[f] and (not reachable[t]): dfs(f,t,EL,ans,reachable,Q-i) elif reachable[t] and (not reachable[f]): dfs(t,f,EL,ans,reachable,Q-i) for i in xrange(1,N): if reachable[i]: print ans[i] else: print 0 solve()