# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
477699 | InternetPerson10 | Spring cleaning (CEOI20_cleaning) | C++17 | 1094 ms | 7632 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<vector<int>> adj;
vector<int> par, chi, le, bad;
int dfs(int n, int pa = -1) {
int childs = 0;
par[n] = pa;
for(int ch : adj[n]) {
if(ch == pa) continue;
childs += dfs(ch, n);
}
if(adj[n].size() == 1) {
le[n] = 1;
return chi[n] = 1;
}
return chi[n] = childs;
}
int main() {
int n, q;
scanf("%d %d", &n, &q);
adj.resize(n);
par.resize(n);
chi.resize(n);
le.resize(n);
for(int i = 1; i < n; i++) {
int x, y;
scanf("%d %d", &x, &y);
x--; y--;
adj[x].push_back(y);
adj[y].push_back(x);
}
int r = 0;
while(adj[r].size() == 1) r++;
dfs(r);
while(q--) {
int k;
scanf("%d", &k);
bad.resize(k);
for(int i = 0; i < k; i++) {
int x;
scanf("%d", &x);
x--;
bad[i] = x;
while(x != -1) {
if(le[x] == 1) {
le[x] = -1;
break;
}
chi[x]++;
x = par[x];
}
}
int ans = n-1+bad.size();
for(int i = 0; i < n; i++) {
if(i == r) continue;
if(chi[i]%2 == 0) ans++;
}
if(chi[r]%2) ans = -1;
printf("%d\n", ans);
for(int g : bad) {
int x = g;
while(x != -1) {
if(le[x] == -1) {
le[x] = 1;
break;
}
chi[x]--;
x = par[x];
}
}
vector<int>().swap(bad);
}
}
컴파일 시 표준 에러 (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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |