Submission #579388

#TimeUsernameProblemLanguageResultExecution timeMemory
579388juggernautMagic Tree (CEOI19_magictree)C++14
6 / 100
2077 ms8064 KiB
#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; 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 (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d%d%d",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
magictree.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d",&x);
      |   ~~~~~^~~~~~~~~
magictree.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |   scanf("%d",&v);
      |   ~~~~~^~~~~~~~~
magictree.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   scanf("%d%d",&d[v],&w[v]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...