传送门
题目大意
额,自己看吧
题解
对于这种有对立关系(只有1对)的时候,我们考虑拆点
x拆为x和x+n
按数值排序后,倒序合并,a和b+n以及b和a+n合并,如果a和b在一个集合中那么输出当前值
注意无冲突情况输出0
var
x:array[0..100005,0..3]of longint;
fa:array[0..40000]of longint;
i,j,k:longint;
n,m,a,b:longint;
procedure sort(l,r: longint);
var i,j,k,a,y: longint;
begin
i:=l; j:=r; a:=x[(l+r) div 2,3];
repeat
while x[i,3]<a do inc(i);
while a<x[j,3] do dec(j);
if not(i>j) then
begin
for k:=1 to 3 do
begin y:=x[i,k]; x[i,k]:=x[j,k]; x[j,k]:=y; end;
inc(i); dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
function get(a:longint):longint;
begin
if fa[a]=a then exit(a);
fa[a]:=get(fa[a]);
exit(fa[a]);
end;
begin
readln(n,m);
for i:=1 to m do
readln(x[i,1],x[i,2],x[i,3]);
sort(1,m); {x[i,3]}
for i:=1 to 2*n do
fa[i]:=i;
for i:=m downto 1 do
begin
a:=get(x[i,1]); b:=get(x[i,2]);
if a=b
then begin writeln(x[i,3]); halt; end
else begin
fa[a]:=get(x[i,2]+n);
fa[b]:=get(x[i,1]+n);
end;
end;
writeln(0);
end.