# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
342474 | 2021-01-02T08:01:03 Z | benedict0724 | Spring cleaning (CEOI20_cleaning) | C++17 | 1000 ms | 14316 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> adj[100002]; int leaf[100002]; int dp[100002]; ll ans = 0; void dfs(int x, int p){ dp[x] = leaf[x]; for(auto u : adj[x]){ if(u != p){ dfs(u, x); dp[x] += dp[u]; } } if(x == 1){ if(adj[x].size() == 1 && leaf[x] == 0){ if(dp[x] == 1){ ans++; return; } else { ans = -1LL; return; } } if(dp[x]%2) { ans = -1LL; return; } else{ ans += dp[x]; return; } } if(dp[x] == 0){ dp[x] = 1; return; } if(dp[x]%2){ ans += dp[x]; dp[x] = 1; return; } ans += dp[x]; dp[x] = 2; } int main() { int n, q; scanf("%d %d", &n, &q); for(int i=1;i<n;i++){ int s, e; scanf("%d %d", &s, &e); adj[s].push_back(e); adj[e].push_back(s); } for(int i=1;i<=q;i++){ fill(leaf, leaf + 30002, 0); int d; scanf("%d", &d); for(int i=1;i<=d;i++){ int l; scanf("%d", &l); leaf[l]++; } ans = 0; dfs(1, -1); printf("%lld\n", ans); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2796 KB | Output is correct |
2 | Execution timed out | 1085 ms | 3456 KB | Time limit exceeded |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 3052 KB | Output is correct |
2 | Correct | 12 ms | 2924 KB | Output is correct |
3 | Correct | 41 ms | 7140 KB | Output is correct |
4 | Correct | 39 ms | 5732 KB | Output is correct |
5 | Correct | 50 ms | 7012 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 3308 KB | Output is correct |
2 | Correct | 14 ms | 3308 KB | Output is correct |
3 | Correct | 56 ms | 14316 KB | Output is correct |
4 | Correct | 63 ms | 13292 KB | Output is correct |
5 | Correct | 62 ms | 13164 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 254 ms | 4284 KB | Output is correct |
2 | Correct | 172 ms | 3564 KB | Output is correct |
3 | Correct | 250 ms | 3680 KB | Output is correct |
4 | Correct | 281 ms | 4076 KB | Output is correct |
5 | Correct | 232 ms | 4204 KB | Output is correct |
6 | Correct | 296 ms | 3988 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1091 ms | 5496 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1089 ms | 6764 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2796 KB | Output is correct |
2 | Execution timed out | 1085 ms | 3456 KB | Time limit exceeded |