# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
578241 | 2022-06-16T09:10:58 Z | temporary_juggernaut | Spring cleaning (CEOI20_cleaning) | C++14 | 1000 ms | 25304 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); 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 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Execution timed out | 1087 ms | 6332 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 9820 KB | Output is correct |
2 | Correct | 24 ms | 9920 KB | Output is correct |
3 | Correct | 56 ms | 14044 KB | Output is correct |
4 | Correct | 86 ms | 16388 KB | Output is correct |
5 | Correct | 101 ms | 18304 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 10580 KB | Output is correct |
2 | Correct | 30 ms | 10516 KB | Output is correct |
3 | Correct | 72 ms | 22220 KB | Output is correct |
4 | Correct | 107 ms | 25304 KB | Output is correct |
5 | Correct | 64 ms | 20540 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 510 ms | 7252 KB | Output is correct |
2 | Correct | 341 ms | 6292 KB | Output is correct |
3 | Correct | 481 ms | 6088 KB | Output is correct |
4 | Correct | 539 ms | 6908 KB | Output is correct |
5 | Correct | 485 ms | 7356 KB | Output is correct |
6 | Correct | 557 ms | 7036 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1075 ms | 8188 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1087 ms | 9804 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Execution timed out | 1087 ms | 6332 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |