Submission #112747

# Submission time Handle Problem Language Result Execution time Memory
112747 2019-05-21T17:28:47 Z klungs Election Campaign (JOI15_election_campaign) C++14
10 / 100
1000 ms 262144 KB

#include<bits/stdc++.h>


#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pf push_front
#define pb2 pop_back
#define pf2 pop_front
#define line printf("\n")
#define pq priority_queue
#define rep(k,i,j) for(int k = (int)i;k<(int)j;k++)
#define repd(k,i,j) for(int k = (int)i;k>=(int)j;k--)
#define ll long long
#define ALL(a) a.begin(),a.end()
#define vi vector<int>

using namespace std;

int INF = 1e9+7;
const int MAXN = 1e5 + 32;

#define vvi vector<vi>

int N, M;
vi A, B, C;
vvi adj;

vvi path;
void bfs(int u, int v, vi &path) {
  vi par(N, -1);
  queue<int> q;
  q.push(u); par[u] = u;
  while (q.size()) {
    int a = q.front(); q.pop();
    for (int b : adj[a]) if (par[b] == -1) {
      q.push(b);
      par[b] = a;
    }
  }
  
  for (int b = v, a = par[v]; b != u; b = par[b], a = par[a]) {
    path.pb(b);    
  }
  path.pb(u);
}

void read(int _N, int _M, vi U, vi V, vi _A, vi _B, vi _C) {
  tie(N, M, A, B, C) = {_N, _M, _A, _B, _C};
  adj.resize(N);
  rep(k, 0, N - 1) {
    U[k]--; V[k]--;
    adj[U[k]].pb(V[k]);
    adj[V[k]].pb(U[k]);
  }
  rep(k, 0, M) {
    A[k]--; B[k]--;
  }
}

int getMaximumVotes(int _N, int _M, vi _U, vi _V, vi _A, vi _B, vi _C) {
  read(_N, _M, _U, _V, _A, _B, _C);
  
  path.resize(M);
  vector<bitset<MAXN>> path_mask(M);
  rep(k, 0, M) {
    bfs(A[k], B[k], path[k]);
    for (auto x : path[k]) 
      path_mask[k][x] = 1;
  }
  
  vvi can(M, vi(M));
  rep(k, 0, M) rep(i, 0, M) {
    if ((path_mask[k] & path_mask[i]).any())
      can[k][i] = 0;
    else 
      can[k][i] = 1;
  }
  
  int ans = 0;
  rep(mask, 0, 1 << M) {
    bool ok = true;
    int val = 0;
    
    vi cur;
    rep(i, 0, M) if ((1 << i) & mask) {
      cur.pb(i); val += C[i];
    }
    
    for (auto a : cur) for (auto b : cur) if (a != b) {
      if (!can[a][b]) 
        ok = false;
    }
    
    if (ok)
      ans = max(ans, val);
  }
  return ans;
}

 
// grader.cpp
#include <stdio.h>
#include <vector>
 
int main() {
  int N, M;
  std::vector<int> U, V;
  std::vector<int> A, B, C;
 
  scanf("%d", &N);
  U.resize(N-1); V.resize(N-1);
 
  for (int i = 0 ; i < N-1 ; i++) {
    scanf("%d %d", &U[i], &V[i]);
  }
  scanf("%d", &M);
  A.resize(M); B.resize(M); C.resize(M);
  for (int i = 0 ; i < M ; i++) {
    scanf("%d %d %d", &A[i], &B[i], &C[i]);
  }
 
  int ans = getMaximumVotes(N, M, U, V, A, B, C);
  printf("%d\n", ans);
  
  return 0;
}

Compilation message

election_campaign.cpp: In function 'int main()':
election_campaign.cpp:116:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &N);
   ~~~~~^~~~~~~~~~
election_campaign.cpp:120:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &U[i], &V[i]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
election_campaign.cpp:122:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &M);
   ~~~~~^~~~~~~~~~
election_campaign.cpp:125:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &A[i], &B[i], &C[i]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 12 ms 640 KB Output is correct
5 Correct 151 ms 9112 KB Output is correct
6 Correct 58 ms 9440 KB Output is correct
7 Correct 108 ms 9520 KB Output is correct
8 Correct 80 ms 9592 KB Output is correct
9 Correct 132 ms 10940 KB Output is correct
10 Correct 78 ms 9592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 4 ms 768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 4 ms 768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 263 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 12 ms 640 KB Output is correct
5 Correct 151 ms 9112 KB Output is correct
6 Correct 58 ms 9440 KB Output is correct
7 Correct 108 ms 9520 KB Output is correct
8 Correct 80 ms 9592 KB Output is correct
9 Correct 132 ms 10940 KB Output is correct
10 Correct 78 ms 9592 KB Output is correct
11 Execution timed out 1043 ms 16760 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 12 ms 640 KB Output is correct
5 Correct 151 ms 9112 KB Output is correct
6 Correct 58 ms 9440 KB Output is correct
7 Correct 108 ms 9520 KB Output is correct
8 Correct 80 ms 9592 KB Output is correct
9 Correct 132 ms 10940 KB Output is correct
10 Correct 78 ms 9592 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Incorrect 4 ms 768 KB Output isn't correct
13 Halted 0 ms 0 KB -