Submission #764190

#TimeUsernameProblemLanguageResultExecution timeMemory
764190AlmaRegions (IOI09_regions)C++17
0 / 100
1288 ms131072 KiB
#include <bits/stdc++.h> using namespace std; vector<int> region; vector<bool> vis, calc; vector<vector<int>> adj, dp, distrib; void dfs(int u, int r) { vis[u] = true; if (region[u] != r) { dp[r][region[u]]++; } for (int v: adj[u]) { if (!vis[v]) dfs(v, r); } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, r, q, h, s, r1, r2; cin >> n >> r >> q; region = vector<int>(n); adj = vector<vector<int>>(n); distrib = vector<vector<int>>(n); cin >> h; h--; region[0] = h; distrib[h].push_back(0); for (int i = 1; i < n; i++) { cin >> s >> h; h--; s--; region[i] = h; distrib[h].push_back(i); adj[s].push_back(i); } // for (int i: region) // cout << i << ' '; // cout << endl; calc = vector<bool> (r, false); dp = vector<vector<int>> (r, vector<int>(r, 0)); while (q--) { cin >> r1 >> r2; r1--; r2--; if (not calc[r1]) { vis = vector<bool>(n, false); for (int i: distrib[r1]) { if (!vis[i]) dfs(i, r1); } calc[r1] = true; } // if (not calc[r2]) { // vis = vector<bool>(n, false); // for (int i: distrib[r2]) { // if (!vis[i]) dfs(i, r2); // } // } cout << dp[r1][r2] << endl; // for (int i = 0; i < r; i++) { // cout << dp[r1][i] << ' '; // } // cout << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...