# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
145156 | tincamatei | Railway (BOI17_railway) | C++14 | 170 ms | 26024 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
const int MAX_K = 50000;
vector<int> graph[1+MAX_N];
vector<int> updates[1+MAX_N];
int lim[MAX_K], subtree[1+MAX_N];
struct SubTreeCnt {
int cnt[MAX_K];
int active;
vector<int> history;
SubTreeCnt() {
for(int i = 0; i < MAX_K; ++i)
cnt[i] = 0;
active = 0;
}
void clear() {
for(auto it: history)
cnt[it]--;
active = 0;
history.clear();
}
void insert(int x) {
if(cnt[x] == 0)
++active;
if(cnt[x] == lim[x] - 1)
--active;
cnt[x]++;
history.push_back(x);
}
int getActive() {
return active;
}
} freq;
struct Edge {
int a, b;
int cnt;
int other(int x) {
return a ^ b ^ x;
}
} edges[MAX_N - 1];
void predfs(int nod, int fatherEdge = -1) {
subtree[nod] = 1;
for(auto it: graph[nod]) {
int son = edges[it].other(nod);
if(it != fatherEdge) {
predfs(son, it);
subtree[nod] += subtree[son];
}
}
}
void updateDfs(int nod, int fatherEdge = -1) {
for(auto it: updates[nod])
freq.insert(it);
for(auto it: graph[nod]) {
int son = edges[it].other(nod);
if(it != fatherEdge)
updateDfs(son, it);
}
}
void dfs(int nod, int fatherEdge = -1) {
int heavyson = -1, heavyedge = -1;
for(auto it: graph[nod]) {
int son = edges[it].other(nod);
if(it != fatherEdge && (heavyson == -1 || (heavyson != -1 && subtree[son] > subtree[heavyson]))) {
heavyson = son;
heavyedge = it;
}
}
for(auto it: graph[nod]) {
int son = edges[it].other(nod);
if(it != fatherEdge && son != heavyson) {
dfs(son, it);
edges[it].cnt = freq.getActive();
freq.clear();
}
}
if(heavyson != -1) {
dfs(heavyson, heavyedge);
edges[heavyedge].cnt = freq.getActive();
for(auto it: graph[nod]) {
int son = edges[it].other(nod);
if(it != fatherEdge && son != heavyson)
updateDfs(son, it);
}
}
for(auto it: updates[nod])
freq.insert(it);
}
int main() {
int n, m, k, a, b, s, nr;
scanf("%d%d%d", &n, &m, &k);
for(int i = 0; i < n - 1; ++i) {
scanf("%d%d", &a, &b);
edges[i].a = a;
edges[i].b = b;
graph[a].push_back(i);
graph[b].push_back(i);
}
for(int i = 0; i < m; ++i) {
scanf("%d", &s);
for(int j = 0; j < s; ++j) {
scanf("%d", &a);
updates[a].push_back(i);
}
lim[i] = s;
}
predfs(1);
dfs(1);
nr = 0;
for(int i = 0; i < n - 1; ++i)
if(edges[i].cnt >= k)
++nr;
printf("%d\n", nr);
for(int i = 0; i < n - 1; ++i)
if(edges[i].cnt >= k)
printf("%d ", i + 1);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |