Submission #419422

#TimeUsernameProblemLanguageResultExecution timeMemory
419422juggernautElection Campaign (JOI15_election_campaign)C++17
10 / 100
1081 ms28756 KiB
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} typedef long long ll; #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 IOI2021SG #define printl(args...)printf(args) #else #define printl(args...)((void)0) #endif int n,tin[100005],tout[100005],up[100005][17],timer; vector<int>g[100005]; void dfs(int v,int p){ tin[v]=++timer; up[v][0]=p; for(int i=1;i<17;i++)up[v][i]=up[up[v][i-1]][i-1]; for(int to:g[v])if(to!=p)dfs(to,v); tout[v]=++timer; } bool upper(int a,int b){ return tin[a]<=tout[b]&&tout[a]>=tout[b]; } int lca(int a,int b){ if(upper(a,b))return a; if(upper(b,a))return b; for(int i=16;i>=0;i--)if(!upper(up[a][i],b))a=up[a][i]; return up[a][0]; } bitset<100005>bt[15]; int m; int cnt[15]; int w[15]; void fll(int id,int x,int y){ while(x^y){ bt[id].set(x,1); x=up[x][0]; } bt[id].set(x,1); } int main(){ scanf("%d",&n); 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,1); scanf("%d",&m); for(int i=0;i<m;i++){ int x,y; scanf("%d%d",&x,&y); int l=lca(x,y); fll(i,x,l); fll(i,y,l); cnt[i]=bt[i].count(); scanf("%d",&w[i]); } int mx=0; for(int mask=0;mask<(1<<m);mask++){ bitset<100005>cur; int sum=0; int total=0; for(int i=0;i<m;i++)if(mask>>i&1){ cur|=bt[i]; sum+=cnt[i]; total+=w[i]; } if(cur.count()==sum)umax(mx,total); } printf("%d",mx); }

Compilation message (stderr)

election_campaign.cpp: In function 'int main()':
election_campaign.cpp:78:23: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   78 |         if(cur.count()==sum)umax(mx,total);
      |            ~~~~~~~~~~~^~~~~
election_campaign.cpp: In function 'void usaco(std::string)':
election_campaign.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
election_campaign.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
election_campaign.cpp: In function 'int main()':
election_campaign.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
election_campaign.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
election_campaign.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     scanf("%d",&m);
      |     ~~~~~^~~~~~~~~
election_campaign.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
election_campaign.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         scanf("%d",&w[i]);
      |         ~~~~~^~~~~~~~~~~~
#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...