class dsu: def __init__(self,n): assert n>0,"n must be Natural" self.n=n self.parents=[-1]*n return def find(self,x): assert xself.parents[y]: x,y=y,x self.parents[x]+=self.parents[y] self.parents[y]=x return def size(self,x): assert xself.d[v]+e[1]: self.d[e[0]]=self.d[v]+e[1] heappush(que,[self.d[e[0]],e[0]]) return self.d class INPUT: def __init__(self): self.l=open(0).read().split()[::-1] self.length=len(self.l) return def stream(self,k=1,f=int,f2=False): assert(-1 return left all listを変数で受け取るとき、必ずlistをTrueにすること。 """ def main(): n,m=pin(2) uf=dsu(n) ds=[pin(3)for i in range(m)] ds=sorted(ds,key=lambda x:x[2],reverse=True) w=float("inf") j=m-1 dk=dijkstra() for i in range(m): w=min(w,ds[i][2]) uf.merge(ds[i][0]-1,ds[i][1]-1) dk.add2(ds[i][0]-1,ds[i][1]-1,1) if uf.same(0,n-1): j=i+1 break while j