답안 #477605

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477605 2021-10-02T19:09:32 Z Abrar_Al_Samit Regions (IOI09_regions) C++17
0 / 100
2 ms 456 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100;
vector <int> g[maxn];
int H[maxn], ans, in[maxn], out[maxn], timer;
vector <int> reg[maxn];
void Euler(int v, int p ){
	in[v] = timer++;
	for(auto it : g[v]) if(it!=p) {
		Euler(it, v);
	}
	out[v] = timer++;
}
bool anc(int x, int y) {
	return in[x]<=in[y] && out[x]>=out[y];
}
int main() {
	int N, R, Q; cin >> N >> R >> Q;
	cin >> H[1];
	reg[H[1]].push_back(1);
	for(int i=2; i<=N; ++i) {
		int p; cin >> p >> H[i];
		g[p].push_back(i);
		g[i].push_back(p);
		reg[H[i]].push_back(i);
	}
	Euler(1, 1);
	while(Q--) {
		int r1, r2; cin >> r1 >> r2;
		int ans = 0;
		for(auto it : reg[r2]) {
			bool ok = false;
			for(auto it2 : reg[r1]) {
				ok |= anc(it2, it);
			}
			ans += ok;
		}
		cout << ans << endl;
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Output isn't correct
2 Incorrect 1 ms 200 KB Output isn't correct
3 Incorrect 2 ms 200 KB Output isn't correct
4 Runtime error 1 ms 328 KB Execution killed with signal 11
5 Runtime error 1 ms 328 KB Execution killed with signal 11
6 Runtime error 1 ms 328 KB Execution killed with signal 11
7 Runtime error 1 ms 328 KB Execution killed with signal 11
8 Runtime error 1 ms 328 KB Execution killed with signal 11
9 Runtime error 1 ms 328 KB Execution killed with signal 11
10 Runtime error 1 ms 328 KB Execution killed with signal 11
11 Runtime error 1 ms 328 KB Execution killed with signal 11
12 Runtime error 1 ms 328 KB Execution killed with signal 11
13 Runtime error 2 ms 456 KB Execution killed with signal 6
14 Runtime error 1 ms 456 KB Execution killed with signal 6
15 Runtime error 1 ms 328 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 328 KB Execution killed with signal 11
2 Runtime error 1 ms 328 KB Execution killed with signal 11
3 Runtime error 1 ms 328 KB Execution killed with signal 11
4 Runtime error 1 ms 328 KB Execution killed with signal 11
5 Runtime error 1 ms 328 KB Execution killed with signal 11
6 Runtime error 1 ms 328 KB Execution killed with signal 11
7 Runtime error 1 ms 328 KB Execution killed with signal 11
8 Runtime error 1 ms 328 KB Execution killed with signal 11
9 Runtime error 1 ms 328 KB Execution killed with signal 11
10 Runtime error 1 ms 328 KB Execution killed with signal 11
11 Runtime error 1 ms 328 KB Execution killed with signal 11
12 Runtime error 1 ms 328 KB Execution killed with signal 11
13 Runtime error 1 ms 328 KB Execution killed with signal 11
14 Runtime error 1 ms 328 KB Execution killed with signal 11
15 Runtime error 1 ms 328 KB Execution killed with signal 11
16 Runtime error 1 ms 328 KB Execution killed with signal 11
17 Runtime error 1 ms 328 KB Execution killed with signal 11