This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |