Cod sursa(job #38979)

Utilizator Bluedrop_demonPandia Gheorghe Bluedrop_demon Data 26 martie 2007 12:25:01
Problema Radiatie Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.4 kb
{
    Problema radiatie
}

Program radiatie;

Const MAXNUM = 15000;

Type    muchie = record
                    x, y : Integer;
                    l : Longint;
                 end;
        muchii = array[1..MAXNUM*2] of muchie;

Var n , m, k, i, j, p, u, auxx, auxy : Integer;
    a : muchii;
    b : array[1..MAXNUM,1..MAXNUM] of Longint;
    l : array[1..MAXNUM] of Integer;
    mx : Longint;
    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 l[p] := auxx;
                    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.