Submission #825230

# Submission time Handle Problem Language Result Execution time Memory
825230 2023-08-14T15:59:27 Z serifefedartar Regions (IOI09_regions) C++17
10 / 100
652 ms 131072 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 100005

vector<vector<int>> graph;
vector<vector<int>> rList;
vector<map<int,int>> mps;
vector<int> region;
void dfs(int node, int parent, map<int,int> here) {
	here[region[node]]++;
	mps[node] = here;
	for (auto u : graph[node]) {
		if (u == parent)
			continue;
		dfs(u, node, here);
	}
}

int main() {
    fast
    int N, R, Q, S, H;
    cin >> N >> R >> Q;

  	graph = vector<vector<int>>(N+1, vector<int>());
  	rList = vector<vector<int>>(R+1, vector<int>());
  	mps = vector<map<int,int>>(N+1, map<int,int>());
  	region = vector<int>(N+1);
  	cin >> region[1];	
  	rList[region[1]].push_back(1);

  	for (int i = 2; i <= N; i++) {
  		cin >> S >> region[i];
 		graph[S].push_back(i);
 		rList[region[i]].push_back(i);
  	}
  	dfs(1, 1, map<int,int>());

  	while (Q--) {
  		int r1, r2;
  		cin >> r1 >> r2;
  		int ans = 0;
  		for (auto u : rList[r2])
  			ans += mps[u][r1];
  		cout << ans << endl;
  	}
}

Compilation message

regions.cpp: In function 'int main()':
regions.cpp:28:21: warning: unused variable 'H' [-Wunused-variable]
   28 |     int N, R, Q, S, H;
      |                     ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 312 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 9 ms 1104 KB Output is correct
6 Correct 31 ms 13520 KB Output is correct
7 Correct 21 ms 4732 KB Output is correct
8 Correct 33 ms 9792 KB Output is correct
9 Runtime error 103 ms 131072 KB Execution killed with signal 9
10 Correct 246 ms 53224 KB Output is correct
11 Runtime error 393 ms 131072 KB Execution killed with signal 9
12 Runtime error 113 ms 131072 KB Execution killed with signal 9
13 Correct 652 ms 75852 KB Output is correct
14 Runtime error 163 ms 131072 KB Execution killed with signal 9
15 Runtime error 105 ms 131072 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 137 ms 131072 KB Execution killed with signal 9
2 Runtime error 154 ms 131072 KB Execution killed with signal 9
3 Runtime error 119 ms 131072 KB Execution killed with signal 9
4 Runtime error 140 ms 131072 KB Execution killed with signal 9
5 Runtime error 109 ms 131072 KB Execution killed with signal 9
6 Runtime error 138 ms 131072 KB Execution killed with signal 9
7 Runtime error 146 ms 131072 KB Execution killed with signal 9
8 Runtime error 125 ms 131072 KB Execution killed with signal 9
9 Runtime error 147 ms 131072 KB Execution killed with signal 9
10 Runtime error 124 ms 131072 KB Execution killed with signal 9
11 Runtime error 173 ms 131072 KB Execution killed with signal 9
12 Runtime error 162 ms 131072 KB Execution killed with signal 9
13 Runtime error 172 ms 131072 KB Execution killed with signal 9
14 Runtime error 157 ms 131072 KB Execution killed with signal 9
15 Runtime error 127 ms 131072 KB Execution killed with signal 9
16 Runtime error 149 ms 131072 KB Execution killed with signal 9
17 Runtime error 127 ms 131072 KB Execution killed with signal 9