답안 #733230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733230 2023-04-30T09:33:29 Z penguin133 Regions (IOI09_regions) C++17
30 / 100
2349 ms 131072 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, r, q;
map <int, int> mp[200005];
vector <int> adj[200005];
int A[200005];
map <int, int> fin[25005];

void dfs(int x, int par){
	mp[x][A[x]]++;
	for(auto i : adj[x]){
		if(i == par)continue;
		dfs(i, x);
		if(mp[i].size() > mp[x].size())swap(mp[x], mp[i]);
		for(auto [j, k] : mp[i])mp[x][j] += k;
	}
	for(auto [i, j] : mp[x])fin[A[x]][i] += j;
}

void solve(){
	cin >> n >> r >> q;
	cin >> A[1];
	for(int i=2;i<=n;i++){
		int x; cin >> x >> A[i];
		adj[x].push_back(i);
	}
	dfs(1, -1);
	while(q--){
		int x, y; cin >> x >> y;
		cout << fin[x][y] << endl;
	}
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

regions.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15544 KB Output is correct
2 Correct 9 ms 15568 KB Output is correct
3 Correct 11 ms 15620 KB Output is correct
4 Correct 15 ms 15636 KB Output is correct
5 Correct 18 ms 15696 KB Output is correct
6 Correct 44 ms 19032 KB Output is correct
7 Correct 38 ms 16852 KB Output is correct
8 Correct 52 ms 17964 KB Output is correct
9 Correct 181 ms 22384 KB Output is correct
10 Correct 101 ms 25652 KB Output is correct
11 Correct 191 ms 22860 KB Output is correct
12 Correct 534 ms 31412 KB Output is correct
13 Correct 108 ms 25660 KB Output is correct
14 Correct 220 ms 24024 KB Output is correct
15 Correct 766 ms 28896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1295 ms 29492 KB Output is correct
2 Correct 974 ms 31884 KB Output is correct
3 Correct 2349 ms 34776 KB Output is correct
4 Runtime error 416 ms 131072 KB Execution killed with signal 9
5 Runtime error 563 ms 131072 KB Execution killed with signal 9
6 Runtime error 481 ms 131072 KB Execution killed with signal 9
7 Runtime error 386 ms 131072 KB Execution killed with signal 9
8 Runtime error 566 ms 131072 KB Execution killed with signal 9
9 Runtime error 369 ms 131072 KB Execution killed with signal 9
10 Runtime error 547 ms 131072 KB Execution killed with signal 9
11 Runtime error 439 ms 131072 KB Execution killed with signal 9
12 Runtime error 526 ms 131072 KB Execution killed with signal 9
13 Runtime error 480 ms 131072 KB Execution killed with signal 9
14 Runtime error 468 ms 131072 KB Execution killed with signal 9
15 Runtime error 384 ms 131072 KB Execution killed with signal 9
16 Runtime error 310 ms 131072 KB Execution killed with signal 9
17 Runtime error 427 ms 131072 KB Execution killed with signal 9