답안 #776330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
776330 2023-07-07T16:51:15 Z I_Love_EliskaM_ 통행료 (IOI18_highway) C++14
51 / 100
151 ms 16932 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
const ll inf = 1e18;
#define pi pair<int,int>
#define f first
#define s second

const int maxn=1e5;
vector<pi> adj[maxn];
pi e[maxn];
vector<int> z;
void dfs(int u, int p) {
  for(auto&ed:adj[u]) {
    int v=ed.f, i=ed.s;
    if (v==p) continue;
    e[i]={u,v};
    z.pb(i);
    dfs(v,u);
  }
}


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void find(int n, vector<int>u, vector<int>v, int a, int b) {
  if (a!=1 || b!=2) exit(0);
  int m=u.size();
  vector<int> f,s;
  ll x;
  forn(it,18) {
    f.clear(), s.clear();
    vector<int> ok(n);
    forn(i,n) ok[i]=rng()&1;
    forn(i,n) (ok[i]?f:s).pb(i);
    if (min(f.size(),s.size())==0) {
      --it; continue;
    }
    vector<int> q(m,0);
    forn(i,m) q[i]=ok[u[i]]==ok[v[i]];
    x = ask(q);
    if (x&1) {
      break;
    }
  }
  if (!(x&1)) exit(0);
  if (f.size()>s.size());
  int l=0, r=f.size()-1;
  while (l<r) {
    int mid=(l+r)>>1;
    vector<int> ok(n);
    for(auto&x:s) ok[x]=1;
    forn(i,mid+1) ok[f[i]]=1;
    vector<int> q(m,0);
    forn(i,m) q[i]=ok[u[i]]==ok[v[i]];
    x = ask(q);
    if (x&1) l=mid+1;
    else r=mid;
  }
  int st = f[r];
  vector<vector<pi>> g(n);
  forn(i,m) {
    g[u[i]].pb({v[i],i});
    g[v[i]].pb({u[i],i});
  }
  vector<int> p(n);
  vector<int> vis(n); vis[st]=1;
  queue<int> q; q.push(st);
  while (q.size()) {
    auto u=q.front();q.pop();
    for(auto&ed:g[u]) {
      int v=ed.f, i=ed.s;
      if (vis[v]) continue;
      vis[v]=1;
      p[v]=i;
      e[i]={u,v};
      q.push(v);
      z.pb(i);
    }
  }
  if (z.size()!=(n-1)) exit(1);
  l=0, r=n-2;
  ll S=ask(vector<int>(m,1));
  while (l<r) {
    int mid=(l+r)>>1;
    vector<int> q(m,1);
    for(int i=mid+1;i<z.size();++i) q[z[i]]=0;
    ll x=ask(q);
    if (x==S) r=mid;
    else l=mid+1;
  }
  answer(st,e[z[r]].s);

}

void find_pair(int n, vector<int>u, vector<int>v, int a, int b) {
  int m=u.size();
  if (m!=n-1) {
    find(n,u,v,a,b);
    return;
  }
  forn(i,n-1) adj[u[i]].pb({v[i],i}), adj[v[i]].pb({u[i],i});
  int k=0; forn(i,n) if (adj[i].size()==1) k=i;
  dfs(k,-1);

  ll s = ask(vector<int>(m,1));

  int l=0, r=n-2;
  while (l<r) {
    int m=(l+r)>>1;
    vector<int> q(n-1);
    forn(i,m+1) q[z[i]]=1;
    ll x=ask(q);
    if (x==s) r=m;
    else l=m+1;
  }

  k = e[z[r]].s;
  //k=0;
  z.clear();
  dfs(k,-1);

  l=0, r=n-2;
  while (l<r) {
    int m=(l+r)>>1;
    vector<int> q(n-1);
    forn(i,m+1) q[z[i]]=1;
    ll x=ask(q);
    if (x==s) r=m;
    else l=m+1;
  }
  answer(k,e[z[r]].s);

}

Compilation message

highway.cpp: In function 'void find(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:85:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   85 |   if (z.size()!=(n-1)) exit(1);
      |       ~~~~~~~~^~~~~~~
highway.cpp:91:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(int i=mid+1;i<z.size();++i) q[z[i]]=0;
      |                     ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2596 KB Output is correct
3 Correct 1 ms 2640 KB Output is correct
4 Correct 1 ms 2640 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 1 ms 2640 KB Output is correct
7 Correct 1 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Correct 1 ms 2640 KB Output is correct
11 Correct 1 ms 2640 KB Output is correct
12 Correct 1 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 7 ms 3376 KB Output is correct
3 Correct 135 ms 9084 KB Output is correct
4 Correct 101 ms 8908 KB Output is correct
5 Correct 79 ms 8908 KB Output is correct
6 Correct 79 ms 8952 KB Output is correct
7 Correct 78 ms 8976 KB Output is correct
8 Correct 128 ms 9004 KB Output is correct
9 Correct 97 ms 8976 KB Output is correct
10 Correct 121 ms 8984 KB Output is correct
11 Correct 98 ms 10644 KB Output is correct
12 Correct 133 ms 11236 KB Output is correct
13 Correct 141 ms 10956 KB Output is correct
14 Correct 92 ms 10512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 4048 KB Output is correct
2 Correct 21 ms 5504 KB Output is correct
3 Correct 39 ms 6848 KB Output is correct
4 Correct 109 ms 15424 KB Output is correct
5 Correct 94 ms 15464 KB Output is correct
6 Correct 82 ms 15424 KB Output is correct
7 Correct 93 ms 15392 KB Output is correct
8 Correct 70 ms 15372 KB Output is correct
9 Correct 61 ms 15376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 14 ms 3352 KB Output is correct
3 Correct 90 ms 7552 KB Output is correct
4 Correct 118 ms 8980 KB Output is correct
5 Correct 120 ms 8972 KB Output is correct
6 Correct 109 ms 8896 KB Output is correct
7 Correct 121 ms 8976 KB Output is correct
8 Correct 98 ms 8908 KB Output is correct
9 Correct 85 ms 8860 KB Output is correct
10 Correct 121 ms 8984 KB Output is correct
11 Correct 106 ms 9848 KB Output is correct
12 Correct 88 ms 10980 KB Output is correct
13 Correct 104 ms 10572 KB Output is correct
14 Correct 127 ms 10960 KB Output is correct
15 Correct 107 ms 8908 KB Output is correct
16 Correct 119 ms 8912 KB Output is correct
17 Correct 101 ms 10176 KB Output is correct
18 Correct 132 ms 10576 KB Output is correct
19 Correct 117 ms 8988 KB Output is correct
20 Correct 103 ms 11408 KB Output is correct
21 Correct 109 ms 9160 KB Output is correct
22 Correct 63 ms 9168 KB Output is correct
23 Correct 90 ms 9092 KB Output is correct
24 Correct 102 ms 9788 KB Output is correct
25 Correct 121 ms 14740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 3792 KB Output is correct
2 Correct 11 ms 3860 KB Output is correct
3 Correct 151 ms 13420 KB Output is correct
4 Runtime error 147 ms 16932 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 2896 KB Output is incorrect: answered not exactly once.
2 Halted 0 ms 0 KB -