#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
int nx[4] = {1,-1,0,0}, ny[4] = {0,0,1,-1};
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
ll lcm(ll a, ll b){return (a / gcd(a, b)) * b;}
const int MAX_R = 504;
const int MAX_N =2e5 + 4;
ll sup[MAX_N][MAX_R];
int reg[MAX_N];
vi adj[MAX_N];
int n, r, q;
int p[MAX_N];
void dfs(int x)
{
for(auto e: adj[x])
{
dfs(e);
for(int h = 1; h <= r;h ++)
{
sup[x][h] += sup[e][h] + (reg[e] == h);
}
}
return;
}
void solve()
{
cin >> n >> r >> q;
cin >> reg[1];
map<int,vi> m;
m[reg[1]].pb(1);
for(int i = 2; i <= n; i ++)
{
cin >> p[i] >> reg[i];
adj[p[i]].pb(i);
m[reg[i]].pb(i);
}
dfs(1);
while(q--)
{
int u, v;
cin >> u >> v;
ll tot = 0ll;
for(auto e: m[u])
tot += sup[e][v];
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int tt = 1;
while(tt--)
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3 ms |
4952 KB |
Time limit exceeded (wall clock) |
2 |
Execution timed out |
4 ms |
5120 KB |
Time limit exceeded (wall clock) |
3 |
Execution timed out |
3 ms |
5064 KB |
Time limit exceeded (wall clock) |
4 |
Execution timed out |
3 ms |
5320 KB |
Time limit exceeded (wall clock) |
5 |
Execution timed out |
4 ms |
6856 KB |
Time limit exceeded (wall clock) |
6 |
Execution timed out |
4 ms |
8264 KB |
Time limit exceeded (wall clock) |
7 |
Execution timed out |
5 ms |
10312 KB |
Time limit exceeded (wall clock) |
8 |
Execution timed out |
7 ms |
12744 KB |
Time limit exceeded (wall clock) |
9 |
Execution timed out |
13 ms |
25280 KB |
Time limit exceeded (wall clock) |
10 |
Execution timed out |
27 ms |
42696 KB |
Time limit exceeded (wall clock) |
11 |
Execution timed out |
36 ms |
63432 KB |
Time limit exceeded (wall clock) |
12 |
Execution timed out |
49 ms |
85056 KB |
Time limit exceeded (wall clock) |
13 |
Execution timed out |
50 ms |
64456 KB |
Time limit exceeded (wall clock) |
14 |
Execution timed out |
69 ms |
112260 KB |
Time limit exceeded (wall clock) |
15 |
Runtime error |
70 ms |
131076 KB |
Execution killed with signal 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
81 ms |
131076 KB |
Execution killed with signal 9 |
2 |
Runtime error |
97 ms |
131076 KB |
Execution killed with signal 9 |
3 |
Runtime error |
78 ms |
131076 KB |
Execution killed with signal 9 |
4 |
Execution timed out |
182 ms |
124380 KB |
Time limit exceeded (wall clock) |
5 |
Runtime error |
167 ms |
131076 KB |
Execution killed with signal 9 |
6 |
Runtime error |
132 ms |
131076 KB |
Execution killed with signal 9 |
7 |
Runtime error |
164 ms |
131076 KB |
Execution killed with signal 9 |
8 |
Runtime error |
193 ms |
131076 KB |
Execution killed with signal 9 |
9 |
Runtime error |
248 ms |
131076 KB |
Execution killed with signal 9 |
10 |
Runtime error |
421 ms |
131076 KB |
Execution killed with signal 9 |
11 |
Runtime error |
347 ms |
131076 KB |
Execution killed with signal 9 |
12 |
Runtime error |
212 ms |
131076 KB |
Execution killed with signal 9 |
13 |
Runtime error |
260 ms |
131076 KB |
Execution killed with signal 9 |
14 |
Runtime error |
226 ms |
131076 KB |
Execution killed with signal 9 |
15 |
Runtime error |
354 ms |
131076 KB |
Execution killed with signal 9 |
16 |
Runtime error |
106 ms |
34568 KB |
Execution killed with signal 11 |
17 |
Runtime error |
405 ms |
131072 KB |
Execution killed with signal 11 |