結果

問題 No.416 旅行会社
ユーザー Tawara
提出日時 2016-08-27 07:22:02
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 719 ms / 4,000 ms
コード長 996 bytes
コンパイル時間 1,333 ms
コンパイル使用メモリ 76,800 KB
実行使用メモリ 216,788 KB
最終ジャッジ日時 2024-12-14 20:01:18
合計ジャッジ時間 9,596 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque
def dfs(b,h,E,ans,reachable,turn):
	q = deque()
	q.append([b,h])
	while q:
		b,h = q.pop()
		if reachable[h]:continue
		reachable[h] = True
		ans[h] = turn
		for nxt in E[h]:
			if b == nxt:continue
			q.append([h,nxt])
def solve():
	ofs = 10**6
	sys.setrecursionlimit(ofs)
	N,M,Q = map(int,raw_input().split())
	reachable = [False]*N
	EL = [[] for i in xrange(N)]
	ans = [0]*N
	Break = set()
	Edges = map(lambda x: map(lambda x:int(x)-1,x.split()),sys.stdin.readlines())
	for i in xrange(Q):
		Break.add(Edges[M+i][0]+Edges[M+i][1]*ofs)
		Break.add(Edges[M+i][0]*ofs+Edges[M+i][1])
	for i in xrange(M):
		f,t = Edges[i]
		if (f+t*ofs) in Break:
			continue
		EL[f].append(t); EL[t].append(f)
	dfs(-1,0,EL,ans,reachable,-1)
	for i in xrange(Q,0,-1):
		f,t = Edges[M+i-1]
		EL[f].append(t); EL[t].append(f)
		if reachable[f]:
			dfs(-1,t,EL,ans,reachable,i)
		elif reachable[t]:
			dfs(-1,f,EL,ans,reachable,i)
	for i in xrange(1,N):
		print ans[i]
solve()
0