Submission #112956

# Submission time Handle Problem Language Result Execution time Memory
112956 2019-05-22T19:56:35 Z imaxblue Highway Tolls (IOI18_highway) C++17
0 / 100
349 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define vi vector<int>
#define vpii vector<pii>
#define vp3i vector<p3i>
#define vpll vector<pll>
#define vp3l vector<p3l>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() ((rand() << 14)+rand())
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846
#include "highway.h"

int n, m, a, b, sz[90005];
ll dis;
vector<pii> v[90005];
bool u[90005], typ;
vector<int> on;
vector<int> out;
bool split = 0;
void dfs0(int N, int P){
  sz[N] = 1;
  for(auto i:v[N]){
    if (i.x == P || u[i.y]) continue;
    dfs0(i.x, N);
    sz[N]+=sz[i.x];
  }
  //cout <<"*" << N << ' ' << sz[N] << endl;
}
void dfs2(int N, int P){
  for(auto i:v[N]){
    if (u[i.y] || i.x == P) continue;
    on[i.y] = typ;
    dfs2(i.x, N);
  }
}
void dfs(int N){
  //cout << "?";
  dfs0(N, -1);
  bool done = 0;
  int R = N;
  int S = sz[N], P = -1, last;
  if (S == 1){
    out.pb(N);
    return;
  }
  while(!done){
    done = 1;
    for(auto i:v[N]){
      if (u[i.y] || i.x == P) continue;
      if (sz[i.x]*2 >= S){
        P = N;
        N = i.x;
        last = i.y;
        done = 0;
        break;
      }
    }
  }
  if (P == -1){
    int hs = 0;
    for(auto i:v[N]){
      if (u[i.y]) continue;
      if (sz[i.x] > hs){
          hs = sz[i.x];
          P = i.x;
          last = i.y;
      }
    }
  }
  //cout << "?" << last << endl;
  on[last] = 1;
  typ = 0;
  dfs2(P, N);
  typ = 1;
  dfs2(N, P);
  bool res1 = (ask(on) - dis > 0);
  typ = 1;
  dfs2(P, N);
  typ = 0;
  dfs2(N, P);
  bool res2 = (ask(on) - dis > 0);

  //cout << "*" << N << ' ' << P << ' ' << last << ' ' << res1 << ' ' << res2 << ' ' << split<< endl;
    typ = 0;
    dfs2(P, N);
    typ = 0;
    dfs2(N, P);
    on[last] = 0;
  if (res1 == 0 && res2 == 0 && split == 0){
    out.pb(N); out.pb(P);
    return;
  } else if (res1 == 0 && res2 == 0){
    out.pb(R);
    return;
  }
  u[last] = 1;
  if (!split){
    if (res1 && res2) split = 1;
    if (res1){
      dfs(N);
    }
    if (res2){
      dfs(P);
    }
  }
  else if (split){
    if (res1){
      dfs(N);
    } else {
      dfs(P);
    }
  }
}
void find_pair(int N,vector<int> U, vector<int> V, int A, int B){
  n = N; m = U.size(); a = A; b = B;
  on = vector<int>(m, 0);
  fox(l, m){
    v[U[l]].pb(mp(V[l], l));
    v[V[l]].pb(mp(U[l], l));
  }
  dis = ask(vector<int>(m, 0));
  dfs(0);
  if (out.size() > 2) exit(1);
  //cout << out.size() << endl;
  answer(out[0], out[1]);
}

Compilation message

highway.cpp: In function 'void dfs(int)':
highway.cpp:94:10: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   on[last] = 1;
          ^
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2424 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2584 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 3704 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2496 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 349 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 Runtime error 334 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -