# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
477699 | 2021-10-03T07:13:22 Z | InternetPerson10 | Spring cleaning (CEOI20_cleaning) | C++17 | 1000 ms | 7632 KB |
#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); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 125 ms | 1912 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 836 KB | Output is correct |
2 | Correct | 10 ms | 832 KB | Output is correct |
3 | Correct | 35 ms | 7252 KB | Output is correct |
4 | Correct | 34 ms | 5552 KB | Output is correct |
5 | Correct | 53 ms | 7632 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1074 ms | 1316 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1056 ms | 2252 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1087 ms | 4928 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1094 ms | 7280 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 125 ms | 1912 KB | Output is correct |
3 | Correct | 11 ms | 836 KB | Output is correct |
4 | Correct | 10 ms | 832 KB | Output is correct |
5 | Correct | 35 ms | 7252 KB | Output is correct |
6 | Correct | 34 ms | 5552 KB | Output is correct |
7 | Correct | 53 ms | 7632 KB | Output is correct |
8 | Execution timed out | 1074 ms | 1316 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |