Cod sursa(job #1595668)

Utilizator AndreiGrigorasAndrei Grigoras AndreiGrigoras Data 10 februarie 2016 14:27:21
Problema Arbore Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <bitset>
#define NMAX 100005
using namespace std ;

ofstream fout ( "arbore.out" ) ;

int N , M , TT[NMAX] , Wage[NMAX] ;
vector<int> SS[NMAX] ;

void update ( int root , int increase )
{
    Wage[root] += increase ;
    for ( vector < int > :: iterator it = SS[root].begin() ; it != SS[root].end() ; ++it )
        Wage[*it] += increase ;
}

void find_employee ( int salary )
{
    for ( int i = 1 ; i <= N ; i++ )
        if ( Wage[i] == salary )
        {
            fout << i << '\n' ;
            break ;
        }
}

void read()
{
    int x , y , operation , increase , root , salary ;
    freopen ( "arbore.in" , "r" , stdin ) ;
    scanf ( "%d %d" , &N , &M ) ;
    for ( int i = 1 ; i <= N - 1 ; i++ )
    {
        scanf ( "%d %d" , &x , &y ) ;
        TT[y] = x ;
        SS[x].push_back(y) ;
    }
    for ( int i = 1 ; i <= M ; i++ )
    {
        scanf ( "%d" , &operation ) ;
        if ( operation == 1 )
        {
            scanf ( "%d %d" , &root , &increase ) ;
            update ( root , increase ) ;
        }
        if ( operation == 2 )
        {
            scanf ( "%d" , &salary ) ;
            find_employee( salary ) ;
        }
    }
}

int main()
{
    read() ;
    return 0;
}