結果

問題 No.416 旅行会社
ユーザー TawaraTawara
提出日時 2016-08-27 00:17:47
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 986 bytes
コンパイル時間 1,921 ms
コンパイル使用メモリ 76,928 KB
実行使用メモリ 254,756 KB
最終ジャッジ日時 2024-04-26 04:19:30
合計ジャッジ時間 16,525 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 503 ms
130,084 KB
testcase_01 AC 79 ms
77,712 KB
testcase_02 AC 81 ms
77,568 KB
testcase_03 AC 81 ms
77,676 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 536 ms
130,208 KB
testcase_11 AC 729 ms
254,756 KB
testcase_12 AC 683 ms
218,708 KB
testcase_13 AC 658 ms
218,492 KB
testcase_14 AC 1,311 ms
184,592 KB
testcase_15 AC 1,454 ms
199,448 KB
testcase_16 AC 1,370 ms
214,924 KB
testcase_17 AC 1,442 ms
222,212 KB
testcase_18 AC 1,374 ms
189,572 KB
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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
	E = [[] for i in xrange(N)]
	ans = [None]*N
	Eset = set()
	BEset = set()
	q = deque()
	for i in xrange(M):
		ft = tuple(map(lambda x: int(x)-1,raw_input().split()))
		Eset.add(ft)
	for i in xrange(Q):
		ft = tuple(map(lambda x: int(x)-1,raw_input().split()))
		BEset.add(ft)
		q.appendleft(ft)
	Eset = Eset - BEset
	for f,t in Eset:
		E[f].append(t)
		E[t].append(f)
	dfs(-1,0,E,ans,reachable,-1)
	for i in xrange(Q):
		f,t = q[i]
		E[f].append(t)
		E[t].append(f)
		if reachable[f] and (not reachable[t]):
			dfs(f,t,E,ans,reachable,Q-i)
		elif reachable[t] and (not reachable[f]):
			dfs(t,f,E,ans,reachable,Q-i)
	for i in xrange(1,N):
		print ans[i]
solve()
	
0