Pagini recente » Cod sursa (job #567782) | Cod sursa (job #1037822) | Cod sursa (job #1473509) | Cod sursa (job #1158294) | Cod sursa (job #38955)
Cod sursa(job #38955)
{
Problema radiatie
}
Program radiatie;
Type muchie = record
x, y : Integer;
l : Longint;
end;
muchii = array[1..30000] of muchie;
Var n , m, k, i, j, p, auxx, auxy : Integer;
a : muchii;
b : array[1..15000,1..15000] of Longint;
l : array[1..15000] of Integer;
cod : boolean;
Function Max( x, y : Longint ) : Longint;
Begin
If x > y then Max := x
else Max := y;
End;
Function pozitie( st, dr : Integer ) : Integer;
Var i, j : Integer;
piv : Longint;
aux : muchie;
Begin
piv := a[st].l;
i := st-1;
j := dr+1;
Repeat
Repeat i := i+1; Until a[i].l >= piv;
Repeat j := j-1; Until a[j].l <= piv;
If i < j then
BEgin
aux := a[i];
a[i] := a[j];
a[j] := aux;
End;
Until i >= j;
pozitie := j;
End;
Procedure qs( st, dr : Integer );
Var m : Integer;
Begin
if st = dr then exit;
m := pozitie( st, dr );
qs( st, m );
qs( m+1, dr );
End;
Begin
Assign( input, 'radiatie.in' );
Reset( input );
Readln( n, m, k );
For i := 1 to m do
Readln( a[i].x, a[i].y, a[i].l );
QS( 1, m );
For i := 1 to n do l[i] := i;
cod := false;
j := 0;
While not cod do
Begin
cod := true;
j := j+1;
If l[a[j].x] <> l[a[j].y] then
Begin
auxy := l[a[j].y];
auxx := l[a[j].x];
b[a[j].x,a[j].y] := a[j].l;
b[a[j].y,a[j].x] := a[j].l;
For p := 1 to n do
If l[p] = auxy then
Begin
b[a[j].x,p] := Max(a[j].l,b[a[j].y,p]);
b[p,a[j].x] := b[a[j].x,p];
l[p] := l[a[j].x];
End
else
If l[p] = auxx then
Begin
b[p,a[j].y] := Max(a[j].l,b[p,a[j].x] );
b[a[j].y,p] := b[p,a[j].y];
End;
End;
For i := 1 to n-1 do
If l[i] <> l[i+1] then
Begin
cod := false;
break;
End;
End;
Assign( output, 'radiatie.out' );
Rewrite( output );
For p := 1 to k do
Begin
Readln( i, j );
Writeln( b[i,j] );
End;
Close( input );
Close( output );
End.