Submission #1024499

#TimeUsernameProblemLanguageResultExecution timeMemory
1024499Ice_manRegions (IOI09_regions)C++14
13 / 100
1136 ms131072 KiB
/**
 ____    ____    ____    __________________    ____    ____    ____
||I ||  ||c ||  ||e ||  ||                ||  ||M ||  ||a ||  ||n ||
||__||  ||__||  ||__||  ||________________||  ||__||  ||__||  ||__||
|/__\|  |/__\|  |/__\|  |/________________\|  |/__\|  |/__\|  |/__\|

*/

#include <iostream>
#include <chrono>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>


#define maxn 200005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;

using namespace std;


typedef long long ll;
typedef pair <ll , ll> pll;
typedef pair <int , int> pii;
typedef long double ld;
typedef unsigned long long ull;




map <int , int> br[maxn];
int n , r , q;
vector <int> v[maxn];
int color[maxn];


void dfs(int node , int par)
{
    for(auto& nb : v[node])
    {
        if(nb == par)
            continue;

        dfs(nb , node);
        br[node][color[nb]]++;
        for(auto& e : br[nb])
            br[node][e.X] += e.Y;

    }
}






void read()
{
    cin >> n >> r >> q;

    for(int i = 1; i <= n; i++)
    {
        if(i == 1)
        {
            cin >> color[i];
            continue;
        }

        int x;
        cin >> x >> color[i];

        v[x].pb(i);
        v[i].pb(x);
    }

    dfs(1 , 0);

    int x , y;
    for(int i = 1; i <= q; i++)
    {
        cin >> x >> y;
        int ans = 0;
        for(int i = 1; i <= n; i++)
            if(color[i] == x)
                ans += br[i][y];
        cout << ans << endl;
        cout.flush();
    }
}










int main()
{

/**#ifdef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#endif*/

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ///startT = std::chrono::high_resolution_clock::now();

    read();


    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...