Submission #825279

# Submission time Handle Problem Language Result Execution time Memory
825279 2023-08-14T16:38:27 Z serifefedartar Regions (IOI09_regions) C++17
11 / 100
648 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) {
	mps[node] = mps[parent];
	mps[node][region[node]]++;
	for (auto u : graph[node]) {
		if (u == parent)
			continue;
		dfs(u, node);
	}
}

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);

  	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 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 4 ms 400 KB Output is correct
5 Correct 7 ms 1192 KB Output is correct
6 Correct 24 ms 7032 KB Output is correct
7 Correct 27 ms 4740 KB Output is correct
8 Correct 36 ms 9800 KB Output is correct
9 Correct 150 ms 67888 KB Output is correct
10 Correct 175 ms 53208 KB Output is correct
11 Runtime error 306 ms 131072 KB Execution killed with signal 9
12 Runtime error 108 ms 131072 KB Execution killed with signal 9
13 Correct 648 ms 75848 KB Output is correct
14 Runtime error 107 ms 131072 KB Execution killed with signal 9
15 Runtime error 106 ms 131072 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 116 ms 131072 KB Execution killed with signal 9
2 Runtime error 114 ms 131072 KB Execution killed with signal 9
3 Runtime error 111 ms 131072 KB Execution killed with signal 9
4 Runtime error 108 ms 131072 KB Execution killed with signal 9
5 Runtime error 108 ms 131072 KB Execution killed with signal 9
6 Runtime error 111 ms 131072 KB Execution killed with signal 9
7 Runtime error 111 ms 131072 KB Execution killed with signal 9
8 Runtime error 117 ms 131072 KB Execution killed with signal 9
9 Runtime error 123 ms 131072 KB Execution killed with signal 9
10 Runtime error 122 ms 131072 KB Execution killed with signal 9
11 Runtime error 139 ms 131072 KB Execution killed with signal 9
12 Runtime error 138 ms 131072 KB Execution killed with signal 9
13 Runtime error 124 ms 131072 KB Execution killed with signal 9
14 Runtime error 128 ms 131072 KB Execution killed with signal 9
15 Runtime error 124 ms 131072 KB Execution killed with signal 9
16 Runtime error 125 ms 131072 KB Execution killed with signal 9
17 Runtime error 129 ms 131072 KB Execution killed with signal 9