# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
579389 | 2022-06-19T04:22:07 Z | temporary_juggernaut | Magic Tree (CEOI19_magictree) | C++14 | 432 ms | 6588 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[100005]; int depth[100005]; int d[100005]; int w[100005]; int a[100005]; bool cmp(int l,int r){ if(d[l]==d[r])return depth[l]>depth[r]; return d[l]<d[r]; } int timer; int tin[100005]; int tout[100005]; int n,m,k; void dfs(int v){ tin[v]=++timer; for(int to:g[v]){ depth[to]=depth[v]+1; dfs(to); } tout[v]=++timer; } bool upper(int a,int b){ return tin[a]<=tin[b]&&tout[a]>=tout[b]; } int main(){ scanf("%d%d%d",&n,&m,&k); for(int i=2;i<=n;i++){ int x; scanf("%d",&x); g[x].push_back(i); } while(m--){ int v; scanf("%d",&v); scanf("%d%d",&d[v],&w[v]); } dfs(1); iota(a+1,a+1+n,1); sort(a+1,a+1+n,cmp); ll ans=0; if(n>20)return 1; for(int mask=0;mask<(1<<n);mask++){ bool flag=true; for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) if((mask>>i&1)&&(mask>>j&1)&&(upper(a[i+1],a[j+1])))flag=false; if(flag){ ll cnt=0; for(int i=0;i<n;i++)if(mask>>i&1)cnt+=w[a[i+1]]; umax(ans,cnt); } } cout<<ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 374 ms | 2656 KB | Output is correct |
3 | Correct | 432 ms | 2656 KB | Output is correct |
4 | Correct | 390 ms | 2644 KB | Output is correct |
5 | Correct | 363 ms | 2664 KB | Output is correct |
6 | Correct | 400 ms | 2656 KB | Output is correct |
7 | Correct | 419 ms | 2656 KB | Output is correct |
8 | Correct | 393 ms | 2656 KB | Output is correct |
9 | Correct | 392 ms | 2660 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 38 ms | 6348 KB | Execution failed because the return code was nonzero |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 2644 KB | Execution failed because the return code was nonzero |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 63 ms | 6588 KB | Execution failed because the return code was nonzero |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 374 ms | 2656 KB | Output is correct |
3 | Correct | 432 ms | 2656 KB | Output is correct |
4 | Correct | 390 ms | 2644 KB | Output is correct |
5 | Correct | 363 ms | 2664 KB | Output is correct |
6 | Correct | 400 ms | 2656 KB | Output is correct |
7 | Correct | 419 ms | 2656 KB | Output is correct |
8 | Correct | 393 ms | 2656 KB | Output is correct |
9 | Correct | 392 ms | 2660 KB | Output is correct |
10 | Runtime error | 61 ms | 6580 KB | Execution failed because the return code was nonzero |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 9 ms | 3412 KB | Execution failed because the return code was nonzero |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 374 ms | 2656 KB | Output is correct |
3 | Correct | 432 ms | 2656 KB | Output is correct |
4 | Correct | 390 ms | 2644 KB | Output is correct |
5 | Correct | 363 ms | 2664 KB | Output is correct |
6 | Correct | 400 ms | 2656 KB | Output is correct |
7 | Correct | 419 ms | 2656 KB | Output is correct |
8 | Correct | 393 ms | 2656 KB | Output is correct |
9 | Correct | 392 ms | 2660 KB | Output is correct |
10 | Runtime error | 2 ms | 2644 KB | Execution failed because the return code was nonzero |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 374 ms | 2656 KB | Output is correct |
3 | Correct | 432 ms | 2656 KB | Output is correct |
4 | Correct | 390 ms | 2644 KB | Output is correct |
5 | Correct | 363 ms | 2664 KB | Output is correct |
6 | Correct | 400 ms | 2656 KB | Output is correct |
7 | Correct | 419 ms | 2656 KB | Output is correct |
8 | Correct | 393 ms | 2656 KB | Output is correct |
9 | Correct | 392 ms | 2660 KB | Output is correct |
10 | Runtime error | 38 ms | 6348 KB | Execution failed because the return code was nonzero |
11 | Halted | 0 ms | 0 KB | - |