# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
342511 | 2021-01-02T09:52:26 Z | leinad2 | Spring cleaning (CEOI20_cleaning) | C++17 | 1000 ms | 9324 KB |
#include<bits/stdc++.h> using namespace std; int n, i, j, k, r, q, a, b, cnt, sz[100010], p[100010], ans; vector<int>adj[100010]; void dfs(int v, int par) { p[v]=par; sz[v]=0; if(adj[v].size()==1) { sz[v]=1; return; } for(int i=0;i<adj[v].size();i++) { int p=adj[v][i]; if(p==par)continue; dfs(p, v); sz[v]+=sz[p]; } } int main() { for(scanf("%d %d", &n, &q);++i<n;) { scanf("%d %d", &a, &b); adj[a].push_back(b); adj[b].push_back(a); } ans=n-1; for(i=0;i++<n;) { if(adj[i].size()>1) { r=i; break; } } dfs(r, 0); for(i=0;i++<n;)sz[i]%=2; for(i=0;i++<n;) { if(sz[i]%2==0)ans++; } while(q--) { cnt=n; vector<int>v; scanf("%d", &a); while(a--) { scanf("%d", &b); ans++; v.push_back(b); adj[b].push_back(++cnt); if(adj[b].size()==2)continue; while(1) { sz[b]=1-sz[b]; if(sz[b]==0)ans++; else ans--; if(b==r)break; b=p[b]; } } if(sz[r]%2) { puts("-1"); goto w; } printf("%d\n", ans-1); w:; for(i=0;i<v.size();i++) { b=v[i]; ans--; adj[b].pop_back(); if(adj[b].size()==1)continue; while(1) { sz[b]=1-sz[b]; if(sz[b]==0)ans++; else ans--; if(b==r)break; b=p[b]; } } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2668 KB | Output is correct |
2 | Correct | 38 ms | 3564 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 3688 KB | Output is correct |
2 | Correct | 17 ms | 3688 KB | Output is correct |
3 | Correct | 36 ms | 7012 KB | Output is correct |
4 | Correct | 50 ms | 6500 KB | Output is correct |
5 | Correct | 76 ms | 7780 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1098 ms | 4200 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1088 ms | 4204 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 65 ms | 5484 KB | Output is correct |
2 | Correct | 94 ms | 5404 KB | Output is correct |
3 | Correct | 66 ms | 4204 KB | Output is correct |
4 | Correct | 72 ms | 5484 KB | Output is correct |
5 | Correct | 71 ms | 5484 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 124 ms | 7532 KB | Output is correct |
2 | Execution timed out | 1057 ms | 9324 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2668 KB | Output is correct |
2 | Correct | 38 ms | 3564 KB | Output is correct |
3 | Correct | 16 ms | 3688 KB | Output is correct |
4 | Correct | 17 ms | 3688 KB | Output is correct |
5 | Correct | 36 ms | 7012 KB | Output is correct |
6 | Correct | 50 ms | 6500 KB | Output is correct |
7 | Correct | 76 ms | 7780 KB | Output is correct |
8 | Execution timed out | 1098 ms | 4200 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |