結果

問題 No.416 旅行会社
ユーザー TawaraTawara
提出日時 2016-08-27 00:48:47
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 960 ms / 4,000 ms
コード長 948 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 76,944 KB
実行使用メモリ 257,024 KB
最終ジャッジ日時 2024-04-26 05:24:36
合計ジャッジ時間 12,759 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 353 ms
136,704 KB
testcase_01 AC 80 ms
75,648 KB
testcase_02 AC 83 ms
76,032 KB
testcase_03 AC 87 ms
75,904 KB
testcase_04 AC 85 ms
75,648 KB
testcase_05 AC 86 ms
75,392 KB
testcase_06 AC 82 ms
75,416 KB
testcase_07 AC 106 ms
78,208 KB
testcase_08 AC 168 ms
81,280 KB
testcase_09 AC 233 ms
85,888 KB
testcase_10 AC 420 ms
136,568 KB
testcase_11 AC 613 ms
257,024 KB
testcase_12 AC 571 ms
225,016 KB
testcase_13 AC 560 ms
225,000 KB
testcase_14 AC 860 ms
155,520 KB
testcase_15 AC 886 ms
170,240 KB
testcase_16 AC 925 ms
183,168 KB
testcase_17 AC 960 ms
192,640 KB
testcase_18 AC 872 ms
162,208 KB
testcase_19 AC 826 ms
175,104 KB
testcase_20 AC 690 ms
136,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def dfs(b,h,E,ans,reachable,turn):
	if reachable[h]:
		return
	reachable[h] = 1
	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 = [0]*N
	EL = [[] for i in xrange(N)]
	ans = [0]*N
	BEset = [set() for i in xrange(N)]
	BE = []
	Edge = [map(lambda x: int(x)-1,raw_input().split()) for i in xrange(M)]
	BE = [map(lambda x: int(x)-1,raw_input().split()) for i in xrange(Q)]
	for i in xrange(Q):
		BEset[BE[i][0]].add(BE[i][1])
	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 in xrange(Q-1,-1,-1):
		f,t = BE[i]
		EL[f].append(t)
		EL[t].append(f)
		if reachable[f]:
			dfs(f,t,EL,ans,reachable,i+1)
		elif reachable[t]:
			dfs(t,f,EL,ans,reachable,i+1)
	for i in xrange(1,N):
		print ans[i]*reachable[i]
solve()
0