# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
302811 | BlancaHM | Regions (IOI09_regions) | C++14 | 8090 ms | 21612 KiB |
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 <iostream>
#include <fstream>
#include <cfloat>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>
#include <climits>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<string> vs;
#define fir first
#define sec second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
vi country;
vvi G;
int N, R, e1, e2, ans;
int dfs(int S) {
int cur = 0;
for (auto v: G[S]) {
cur += dfs(v);
if (country[v] == e2) cur++;
}
if (country[S] == e1) ans += cur;
return cur;
}
int main() {
int Q, cn, sup;
scanf("%d %d %d", &N, &R, &Q);
G.assign(N, vi());
country = vi(N);
cin >> cn;
country[0] = cn;
map<pii, int> past;
for (int i = 1; i < N; i++) {
scanf("%d %d", &sup, &cn);
G[sup-1].push_back(i);
country[i] = cn;
}
while(Q--) {
scanf("%d %d", &e1, &e2);
if (past.find(mp(e1, e2)) != past.end()) {
printf("%d\n", past[mp(e1, e2)]);
fflush(stdout);
continue;
}
ans = 0;
dfs(0);
printf("%d\n", ans);
fflush(stdout);
past[mp(e1, e2)] = ans;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |