# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
578248 | 2022-06-16T09:17:19 Z | temporary_juggernaut | Spring cleaning (CEOI20_cleaning) | C++14 | 1000 ms | 25096 KB |
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; typedef long long ll; typedef long double ld; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef juggernaut #define printl(args...) printf(args) #else #define printl(args...) 0 #endif vector<int>g[200005]; ll dp[200005][2]; void dfs(int v,int p){ for(int to:g[v])if(to^p)dfs(to,v); if(g[v].size()==1&&p){ dp[v][0]=1e15; dp[v][1]=0; return; } dp[v][0]=dp[v][1]=0; vector<pair<ll,int>>vec; for(int to:g[v])if(to^p)vec.push_back(make_pair(dp[to][1]-dp[to][0],to)); sort(vec.begin(),vec.end()); { dp[v][1]+=dp[vec[0].sc][1]+1; for(int i=1;i<(int)vec.size();i++){ if(i+1<(int)vec.size()){ dp[v][1]+=min(dp[vec[i].sc][0]+dp[vec[i+1].sc][0]+4,dp[vec[i].sc][1]+dp[vec[i+1].sc][1]+2); i++; }else dp[v][1]+=dp[vec[i].sc][0]+2; } } { for(int i=0;i<(int)vec.size();i++){ if(i+1<(int)vec.size()){ dp[v][0]+=min(dp[vec[i].sc][0]+dp[vec[i+1].sc][0]+4,dp[vec[i].sc][1]+dp[vec[i+1].sc][1]+2); i++; }else dp[v][0]+=dp[vec[i].sc][0]+2; } } } int main(){ int n,q; scanf("%d%d",&n,&q); for(int i=1;i^n;i++){ int x,y; scanf("%d%d",&x,&y); g[x].push_back(y); g[y].push_back(x); } dfs(1,0); if(true){ if(__builtin_popcount(n+1)==1){ while(q--){ int m; scanf("%d",&m); int leaf=0; int cnt=0; while(m--){ int x; scanf("%d",&x); if(g[x].size()==1)leaf++; else cnt++; } if(cnt&1)puts("-1"); else printf("%lld\n",dp[1][0]+cnt+leaf); } return 0; } } while(q--){ int m; scanf("%d",&m); vector<int>vec; int timer=n+1; while(m--){ int x; scanf("%d",&x); vec.push_back(x); g[x].push_back(timer); g[timer].push_back(x); timer++; } dfs(1,0); ll ans=dp[1][g[1].size()==1]; if(ans>=(1e15))ans=-1; printf("%lld\n",ans); timer=n+1; for(int &x:vec){ g[x].pop_back(); g[timer].clear(); timer++; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4948 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 9668 KB | Output is correct |
2 | Correct | 29 ms | 9688 KB | Output is correct |
3 | Correct | 70 ms | 13972 KB | Output is correct |
4 | Correct | 94 ms | 16252 KB | Output is correct |
5 | Correct | 127 ms | 18204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 10444 KB | Output is correct |
2 | Correct | 30 ms | 10452 KB | Output is correct |
3 | Correct | 79 ms | 22084 KB | Output is correct |
4 | Correct | 149 ms | 25096 KB | Output is correct |
5 | Correct | 88 ms | 20388 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 643 ms | 7128 KB | Output is correct |
2 | Correct | 424 ms | 6180 KB | Output is correct |
3 | Correct | 619 ms | 5948 KB | Output is correct |
4 | Correct | 645 ms | 6780 KB | Output is correct |
5 | Correct | 596 ms | 7124 KB | Output is correct |
6 | Correct | 660 ms | 6792 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 77 ms | 8488 KB | Output is correct |
2 | Incorrect | 48 ms | 8208 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1090 ms | 9780 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4948 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |