Submission #1024495

# Submission time Handle Problem Language Result Execution time Memory
1024495 2024-07-16T06:02:18 Z Ice_man Regions (IOI09_regions) C++14
0 / 100
216 ms 131072 KB
/**
 ____    ____    ____    __________________    ____    ____    ____
||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;
        
    }
}










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 time Memory Grader output
1 Execution timed out 2 ms 14936 KB Time limit exceeded (wall clock)
2 Execution timed out 2 ms 14936 KB Time limit exceeded (wall clock)
3 Execution timed out 2 ms 14936 KB Time limit exceeded (wall clock)
4 Execution timed out 2 ms 14936 KB Time limit exceeded (wall clock)
5 Execution timed out 3 ms 15448 KB Time limit exceeded (wall clock)
6 Execution timed out 10 ms 21616 KB Time limit exceeded (wall clock)
7 Execution timed out 4 ms 16216 KB Time limit exceeded (wall clock)
8 Execution timed out 6 ms 18520 KB Time limit exceeded (wall clock)
9 Execution timed out 85 ms 81744 KB Time limit exceeded (wall clock)
10 Execution timed out 23 ms 25644 KB Time limit exceeded (wall clock)
11 Execution timed out 48 ms 46964 KB Time limit exceeded (wall clock)
12 Runtime error 166 ms 131072 KB Execution killed with signal 9
13 Execution timed out 22 ms 21584 KB Time limit exceeded (wall clock)
14 Execution timed out 48 ms 39248 KB Time limit exceeded (wall clock)
15 Runtime error 161 ms 131072 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 165 ms 131072 KB Execution killed with signal 9
2 Execution timed out 170 ms 123728 KB Time limit exceeded (wall clock)
3 Runtime error 168 ms 131072 KB Execution killed with signal 9
4 Runtime error 175 ms 131072 KB Execution killed with signal 9
5 Runtime error 163 ms 131072 KB Execution killed with signal 9
6 Runtime error 177 ms 131072 KB Execution killed with signal 9
7 Runtime error 180 ms 131072 KB Execution killed with signal 9
8 Runtime error 174 ms 131072 KB Execution killed with signal 9
9 Runtime error 171 ms 131072 KB Execution killed with signal 9
10 Runtime error 170 ms 131072 KB Execution killed with signal 9
11 Runtime error 216 ms 131072 KB Execution killed with signal 9
12 Runtime error 182 ms 131072 KB Execution killed with signal 9
13 Runtime error 194 ms 131072 KB Execution killed with signal 9
14 Runtime error 214 ms 131072 KB Execution killed with signal 9
15 Runtime error 164 ms 131072 KB Execution killed with signal 9
16 Runtime error 173 ms 131072 KB Execution killed with signal 9
17 Runtime error 188 ms 131072 KB Execution killed with signal 9