# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
900482 | 2024-01-08T11:04:05 Z | Trisanu_Das | Spring cleaning (CEOI20_cleaning) | C++17 | 1000 ms | 15356 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 3160 KB | Output is correct |
2 | Execution timed out | 1064 ms | 4848 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 3676 KB | Output is correct |
2 | Correct | 8 ms | 3748 KB | Output is correct |
3 | Correct | 21 ms | 7880 KB | Output is correct |
4 | Correct | 22 ms | 6868 KB | Output is correct |
5 | Correct | 28 ms | 8212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 4188 KB | Output is correct |
2 | Correct | 8 ms | 4188 KB | Output is correct |
3 | Correct | 33 ms | 15356 KB | Output is correct |
4 | Correct | 39 ms | 14948 KB | Output is correct |
5 | Correct | 30 ms | 14416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 167 ms | 5536 KB | Output is correct |
2 | Correct | 113 ms | 4472 KB | Output is correct |
3 | Correct | 156 ms | 4184 KB | Output is correct |
4 | Correct | 196 ms | 4828 KB | Output is correct |
5 | Correct | 162 ms | 4956 KB | Output is correct |
6 | Correct | 203 ms | 5140 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1059 ms | 6484 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1028 ms | 8016 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 3160 KB | Output is correct |
2 | Execution timed out | 1064 ms | 4848 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |