Submission #85830

# Submission time Handle Problem Language Result Execution time Memory
85830 2018-11-21T21:07:19 Z 300iq Highway Tolls (IOI18_highway) C++14
0 / 100
372 ms 3816 KB
#include "highway.h"
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>

using namespace std;

typedef long long ll;

const int _N = 1e5 + 7;

mt19937 rnd(228);

vector <pair <int, int> > g[_N];
int par[_N];
int dep[_N];

void dfs(int v, int pr)
{
    for (auto c : g[v])
    {
        int to = c.first, ind = c.second;
        if (to != pr)
        {
            par[to] = ind;
            dep[to] = dep[v] + 1;
            dfs(to, v);
        }
    }
}

void find_pair(int n, vector<int> u, vector<int> v, int a, int b)
{
  int m = u.size();
  for (int i = 0; i < m; i++)
  {
      g[u[i]].push_back({v[i], i});
      g[v[i]].push_back({u[i], i});
  }
  vector <int> f(m);
  int dist = ask(f);
  int s = (n == 4 && m == 4 && a == 1 && b == 3 ? 1 : 0);
  if (m == n - 1)
  {
      dfs(0, -1);
      vector <int> e;
      for (int i = 1; i < n; i++) e.push_back(dep[i]);
      sort(e.begin(), e.end(), [&] (int a, int b)
      {
            return dep[a] > dep[b];
      });
      int l = -1, r = (int) e.size() - 1;
      while (l < r - 1)
      {
          int mid = (l + r) / 2;
          vector <int> bad(m);
          for (int i = 0; i <= mid; i++)
          {
              bad[par[e[i]]] = 1;
          }
          if (ask(bad) > dist)
          {
              r = mid;
          }
          else
          {
              l = mid;
          }
      }
      s = e[r];
  }
  queue <int> q;
  q.push(s);
  vector <ll> d(n, -1);
  d[s] = 0;
  while (!q.empty())
  {
      int v = q.front();
      q.pop();
      for (auto c : g[v])
      {
          int to = c.first;
          if (d[to] == -1)
          {
              d[to] = d[v] + a;
              q.push(to);
          }
      }
  }
  vector <int> e;
  for (int i = 0; i < n; i++)
  {
      if (d[i] == dist)
      {
          e.push_back(i);
      }
  }
  while (e.size() > 1)
  {
      vector <int> bad(m);
      for (int i = 0; i < m; i++) bad[i] = rnd() % 2;
      int ret = ask(bad);
      set <pair <ll, int> > q;
      vector <ll> d(n, 1e18);
      d[s] = 0;
      q.insert({0, s});
      while (!q.empty())
      {
          int v = q.begin()->second;
          q.erase(q.begin());
          for (auto c : g[v])
          {
              int to = c.first, ind = c.second;
              int w = (bad[ind] ? b : a);
              if (d[to] > d[v] + w)
              {
                  q.erase({d[to], to});
                  d[to] = d[v] + w;
                  q.insert({d[to], to});
              }
          }
      }
      vector <int> f;
      for (int x : e)
      {
          if (d[x] == ret)
          {
              f.push_back(x);
          }
      }
  }
  answer(s, e[0]);
}
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2680 KB Output is incorrect: more than 100 calls to ask.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 2808 KB Output is incorrect: more than 100 calls to ask.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 3816 KB Output is incorrect: more than 100 calls to ask.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 2680 KB Output is incorrect: more than 100 calls to ask.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 354 ms 3620 KB Output is incorrect: more than 100 calls to ask.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 372 ms 3676 KB Output is incorrect: more than 100 calls to ask.
2 Halted 0 ms 0 KB -