結果

問題 No.1473 おでぶなおばけさん
ユーザー 👑 timitimi
提出日時 2021-04-26 17:03:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 978 ms / 2,000 ms
コード長 1,029 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 131,720 KB
最終ジャッジ日時 2023-09-18 11:36:01
合計ジャッジ時間 30,375 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
71,784 KB
testcase_01 AC 100 ms
71,620 KB
testcase_02 AC 885 ms
125,296 KB
testcase_03 AC 730 ms
117,648 KB
testcase_04 AC 576 ms
103,580 KB
testcase_05 AC 349 ms
86,120 KB
testcase_06 AC 776 ms
120,808 KB
testcase_07 AC 978 ms
131,184 KB
testcase_08 AC 971 ms
131,112 KB
testcase_09 AC 954 ms
130,264 KB
testcase_10 AC 437 ms
93,096 KB
testcase_11 AC 437 ms
92,484 KB
testcase_12 AC 434 ms
92,964 KB
testcase_13 AC 311 ms
87,128 KB
testcase_14 AC 256 ms
85,668 KB
testcase_15 AC 403 ms
91,616 KB
testcase_16 AC 425 ms
91,608 KB
testcase_17 AC 139 ms
78,364 KB
testcase_18 AC 150 ms
78,496 KB
testcase_19 AC 491 ms
91,372 KB
testcase_20 AC 726 ms
114,068 KB
testcase_21 AC 704 ms
104,552 KB
testcase_22 AC 818 ms
113,808 KB
testcase_23 AC 749 ms
112,060 KB
testcase_24 AC 793 ms
111,156 KB
testcase_25 AC 901 ms
113,128 KB
testcase_26 AC 970 ms
114,980 KB
testcase_27 AC 381 ms
87,744 KB
testcase_28 AC 910 ms
130,204 KB
testcase_29 AC 612 ms
102,540 KB
testcase_30 AC 700 ms
109,728 KB
testcase_31 AC 767 ms
131,720 KB
testcase_32 AC 563 ms
121,736 KB
testcase_33 AC 527 ms
111,872 KB
testcase_34 AC 415 ms
95,768 KB
testcase_35 AC 380 ms
93,740 KB
testcase_36 AC 607 ms
100,360 KB
testcase_37 AC 675 ms
109,620 KB
testcase_38 AC 270 ms
82,308 KB
testcase_39 AC 437 ms
92,884 KB
testcase_40 AC 439 ms
92,900 KB
testcase_41 AC 430 ms
91,068 KB
testcase_42 AC 431 ms
91,064 KB
testcase_43 AC 295 ms
105,640 KB
testcase_44 AC 293 ms
105,636 KB
testcase_45 AC 301 ms
105,644 KB
testcase_46 AC 832 ms
112,808 KB
testcase_47 AC 870 ms
119,452 KB
testcase_48 AC 806 ms
114,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int, input().split())
D=[]
for i in range(M):
  s,t,d=map(int, input().split())
  D.append((d,s,t))
D=sorted(D)[::-1]
par=[i for i in range(N)]
rank=[0]*(N)
friend=[0]*N
block=[0]*N
size=[1]*N
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
 
#同じ集合か判定
def same(x,y):
  return find(x)==find(y)
 
def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1
E=[[]for i in range(N)] 
limit=0
for d,s,t in D:
  #print(s,t,d,limit)
  if limit>d:
    break
  s-=1
  t-=1
  union(s,t)
  E[s].append(t)
  E[t].append(s)
  if same(0,N-1):
    answ=d
    limit=d
from collections import deque
d=deque()
d.append((0,0,0))
F=[N]*N
while d:
  now,pre,num=d.popleft()
  for nex in E[now]:
    if nex==N-1:
      print(answ,num+1)
      exit()
    if nex!=pre:
      if num+1<F[nex]:
        F[nex]=num
        d.append((nex,now,num+1))
0