Submission #419422

# Submission time Handle Problem Language Result Execution time Memory
419422 2021-06-07T05:52:21 Z juggernaut Election Campaign (JOI15_election_campaign) C++17
10 / 100
1000 ms 28756 KB
#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

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 time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 3 ms 2756 KB Output is correct
4 Correct 575 ms 2832 KB Output is correct
5 Correct 650 ms 14788 KB Output is correct
6 Correct 629 ms 19120 KB Output is correct
7 Correct 642 ms 17476 KB Output is correct
8 Correct 616 ms 15040 KB Output is correct
9 Correct 660 ms 16672 KB Output is correct
10 Correct 639 ms 15044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2636 KB Output is correct
2 Runtime error 6 ms 5324 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2636 KB Output is correct
2 Runtime error 6 ms 5324 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 93 ms 28756 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 3 ms 2756 KB Output is correct
4 Correct 575 ms 2832 KB Output is correct
5 Correct 650 ms 14788 KB Output is correct
6 Correct 629 ms 19120 KB Output is correct
7 Correct 642 ms 17476 KB Output is correct
8 Correct 616 ms 15040 KB Output is correct
9 Correct 660 ms 16672 KB Output is correct
10 Correct 639 ms 15044 KB Output is correct
11 Execution timed out 1081 ms 2764 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 3 ms 2756 KB Output is correct
4 Correct 575 ms 2832 KB Output is correct
5 Correct 650 ms 14788 KB Output is correct
6 Correct 629 ms 19120 KB Output is correct
7 Correct 642 ms 17476 KB Output is correct
8 Correct 616 ms 15040 KB Output is correct
9 Correct 660 ms 16672 KB Output is correct
10 Correct 639 ms 15044 KB Output is correct
11 Correct 5 ms 2636 KB Output is correct
12 Runtime error 6 ms 5324 KB Execution killed with signal 6
13 Halted 0 ms 0 KB -