답안 #883335

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883335 2023-12-05T07:32:31 Z serifefedartar Regions (IOI09_regions) C++17
30 / 100
707 ms 18212 KB
#include <bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 9;
const ll LOGN = 21;
const ll MAXN = 2e5 +  100;

vector<vector<int>> graph;
int reg[MAXN], dp[505][505];
vector<int> cnt[MAXN];
void dfs(int node, int parent) {
	cnt[node][reg[node]]++;
	for (int reg_other = 1; reg_other <= 500; reg_other++)
		dp[reg_other][reg[node]] += cnt[node][reg_other];
	for (auto u : graph[node]) {
		swap(cnt[u], cnt[node]);
		dfs(u, node);
	}
	cnt[node][reg[node]]--;
	swap(cnt[parent], cnt[node]);
}

int main() {
	fast
	int N, R, Q, a, b;
	cin >> N >> R >> Q;

	graph = vector<vector<int>>(N+1, vector<int>());
	cin >> reg[1];
	for (int i = 2; i <= N; i++) {
		int S;
		cin >> S >> reg[i];
		graph[S].push_back(i);
	}

	if (R <= 500) {
		cnt[1] = vector<int>(505, 0);
		dfs(1, 1);
		for (int i = 0; i < Q; i++) {
			cin >> a >> b;
			cout << dp[a][b] << endl;
		}
	} else {
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6744 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 3 ms 6708 KB Output is correct
5 Correct 4 ms 6900 KB Output is correct
6 Correct 11 ms 6744 KB Output is correct
7 Correct 15 ms 6744 KB Output is correct
8 Correct 17 ms 6744 KB Output is correct
9 Correct 28 ms 7436 KB Output is correct
10 Correct 50 ms 7256 KB Output is correct
11 Correct 49 ms 7652 KB Output is correct
12 Correct 63 ms 8024 KB Output is correct
13 Correct 75 ms 7768 KB Output is correct
14 Correct 90 ms 8280 KB Output is correct
15 Correct 107 ms 11964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 443 ms 11824 KB Output is correct
2 Correct 574 ms 10316 KB Output is correct
3 Correct 707 ms 14304 KB Output is correct
4 Incorrect 7 ms 8280 KB Unexpected end of file - int32 expected
5 Incorrect 8 ms 8792 KB Unexpected end of file - int32 expected
6 Incorrect 10 ms 9304 KB Unexpected end of file - int32 expected
7 Incorrect 13 ms 10372 KB Unexpected end of file - int32 expected
8 Incorrect 17 ms 12064 KB Unexpected end of file - int32 expected
9 Incorrect 28 ms 14640 KB Unexpected end of file - int32 expected
10 Incorrect 31 ms 16440 KB Unexpected end of file - int32 expected
11 Incorrect 35 ms 15232 KB Unexpected end of file - int32 expected
12 Incorrect 37 ms 17180 KB Unexpected end of file - int32 expected
13 Incorrect 32 ms 16720 KB Unexpected end of file - int32 expected
14 Incorrect 37 ms 16936 KB Unexpected end of file - int32 expected
15 Incorrect 34 ms 17744 KB Unexpected end of file - int32 expected
16 Incorrect 34 ms 17856 KB Unexpected end of file - int32 expected
17 Incorrect 35 ms 18212 KB Unexpected end of file - int32 expected