比赛 防止颓废的小练习v0.2 评测结果 AAAAAAAAAA
题目名称 关押罪犯 最终得分 100
用户昵称 Ten.X 运行时间 0.201 s
代码语言 Pascal 内存使用 1.46 MiB
提交时间 2016-10-18 14:10:27
显示代码纯文本
var a,b,c:array[0..100009] of longint;f:array[0..40009] of longint;
    x,y,ans,i,n,m:longint;
procedure qsort(l,r:longint);
var i,j,bi,ti:longint; 
begin 
i:=l;
j:=r; 
bi:=c[(l+r) div 2];
repeat
while c[i]>bi do inc(i);
while c[j]<bi do dec(j);
if i<=j then
begin
ti:=a[i];a[i]:=a[j];a[j]:=ti;
ti:=b[i];b[i]:=b[j];b[j]:=ti; 
ti:=c[i];c[i]:=c[j];c[j]:=ti; 
inc(i); dec(j); 
end; 
until i>j; 
if l<j then qsort(l,j); 
if i<r then qsort(i,r); 
end;
function find(x:longint):longint; 
begin 
if f[x]=x then exit(x); 
f[x]:=find(f[x]); 
exit(f[x]); 
end;
begin
assign(input,'prison1.in');reset(input); 
assign(output,'prison1.out');rewrite(output); 
read(n,m); 
for i:=1 to m do read(a[i],b[i],c[i]); 
qsort(1,m);  
for i:=1 to 2*n do f[i]:=i;
for i:=1 to m do 
begin 
if find(a[i])=find(b[i]) then
begin
ans:=c[i];
break;
end else
begin
f[find(a[i])]:=find(b[i]+n);
f[find(b[i])]:=find(a[i]+n);
end;
end;
write(ans);
close(input);close(output);
end.