| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 106492 | wilwxk | Regions (IOI09_regions) | C++11 | 565 ms | 131072 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN=2e5+5;
const int MAXC=25005;
const int T=200;
vector<int> g[MAXN];
int cor[MAXN], tam[MAXN], ind[MAXN], indg[MAXN];
int dp[MAXN][(MAXN/T)+5];
int precalc[(MAXN/T)+5][MAXC];
vector<int> v, lista[MAXN], grandes;
int n, r, q;
void dfs(int cur, int p) {
tam[cur]=1;
ind[cur]=v.size();
v.push_back(cor[cur]);
for(int i=1; i<=r; i++) dp[cur][i]=dp[p][i];
if(cur!=p) dp[cur][indg[cor[p]]]++;
for(auto viz : g[cur]) {
if(viz==p) continue;
dfs(viz, cur);
tam[cur]+=tam[viz];
}
}
int main() {
scanf("%d %d %d", &n, &r, &q);
grandes.push_back(0);
for(int i=1; i<=n; i++) {
int a; if(i!=1)scanf("%d", &a);
scanf("%d", &cor[i]);
if(i!=1) g[i].push_back(a), g[a].push_back(i);
lista[cor[i]].push_back(i);
if(lista[cor[i]].size()==1) grandes.push_back(cor[i]), indg[cor[i]]=grandes.size()-1;
}
v.push_back(0);
dfs(1, 1);
// for(int i=1; i<=n; i++) {
// printf("vertice %d: tam %d // cor %d // ind %d\n ", i, tam[i], cor[i], ind[i]);
// for(int j=1; j<grandes.size(); j++) printf("%d ", dp[i][j]); printf("\n");
// }
for(int i=1; i<=n; i++) {
for(int j=1; j<=r; j++) {
precalc[j][cor[i]]+=dp[i][j];
// printf("precalc[%d][cor[%d]=%d]= %d\n", j, i, cor[i], precalc[j][cor[i]]);
}
}
// for(int i=1; i<=r; i++) printf("cor %d: lista[].size()= %d // indg[]= %d\n", i, lista[i].size(), indg[i]);
while(q--) {
int a, b; scanf("%d %d", &a, &b);
if(indg[a]) {
printf("%d\n", precalc[indg[a]][b]);
fflush(stdout);
continue;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
