Submission #112962

# Submission time Handle Problem Language Result Execution time Memory
112962 2019-05-22T20:13:18 Z imaxblue Highway Tolls (IOI18_highway) C++17
0 / 100
357 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;
      }
    }
  }
  bool spec=0;
  if (P == -1){
    spec= 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 (spec){
      if (res2) dfs(P);
      else dfs(N);
      return;
    }
    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);
  //cout << out.size() << endl;
  answer(out[0], out[1]);
}

Compilation message

highway.cpp: In function 'void dfs(int)':
highway.cpp:96:10: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   on[last] = 1;
          ^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2424 KB Output is correct
2 Correct 5 ms 2428 KB Output is correct
3 Correct 5 ms 2424 KB Output is correct
4 Correct 4 ms 2424 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 7 ms 2424 KB Output is correct
7 Correct 5 ms 2424 KB Output is correct
8 Correct 5 ms 2424 KB Output is correct
9 Correct 5 ms 2428 KB Output is correct
10 Correct 4 ms 2344 KB Output is correct
11 Incorrect 5 ms 2424 KB Output is incorrect: {s, t} is wrong.
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2424 KB Output is correct
2 Correct 22 ms 3096 KB Output is correct
3 Incorrect 259 ms 7988 KB Output is incorrect: {s, t} is wrong.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 3572 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2580 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 357 ms 262148 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 340 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -