Submission #776336

# Submission time Handle Problem Language Result Execution time Memory
776336 2023-07-07T17:09:13 Z I_Love_EliskaM_ Highway Tolls (IOI18_highway) C++14
69 / 100
192 ms 17784 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=2e5;
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) {
  int shift=0;
  while (!((a^b)&1)) {
  	++shift;
  	a>>=1;
  	b>>=1;
  }
  int m=u.size();
  vector<int> f,s;
  ll x;
  int Z=a&1; Z^=1;
  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);
    forn(i,m) q[i]=(ok[u[i]]==ok[v[i]])^Z;
    x = ask(q);
    x>>=shift;
    if (x&1) {
    	//cout<<"!!! : "<<a<<' '<<b<<'\n';
    	//cout<<ask(q)<<'\n';
    	//for(auto&x:f) cout<<x<<' '; cout<<'\n';
    	//for(auto&y:s) cout<<y<<' '; cout<<'\n';
      break;
    }
  }
  if (!(x&1)) exit(0);
  if (f.size()>s.size());
  assert(f.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]])^Z;
    x = ask(q);
    x>>=shift;
    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> 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;
      e[i]={u,v};
      q.push(v);
      z.pb(i);
    }
  }
  l=0, r=n-2;
  ll S=ask(vector<int>(m,1))>>shift;
  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);
	x>>=shift;
    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:101:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for(int i=mid+1;i<z.size();++i) q[z[i]]=0;
      |                     ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 2 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 2 ms 4944 KB Output is correct
12 Correct 2 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 9 ms 5616 KB Output is correct
3 Correct 121 ms 11328 KB Output is correct
4 Correct 143 ms 11320 KB Output is correct
5 Correct 97 ms 11324 KB Output is correct
6 Correct 81 ms 11244 KB Output is correct
7 Correct 96 ms 11324 KB Output is correct
8 Correct 106 ms 11320 KB Output is correct
9 Correct 84 ms 11260 KB Output is correct
10 Correct 107 ms 11328 KB Output is correct
11 Correct 106 ms 12984 KB Output is correct
12 Correct 119 ms 13628 KB Output is correct
13 Correct 97 ms 13304 KB Output is correct
14 Correct 126 ms 12860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6352 KB Output is correct
2 Correct 25 ms 7848 KB Output is correct
3 Correct 23 ms 9232 KB Output is correct
4 Correct 64 ms 17720 KB Output is correct
5 Correct 65 ms 17772 KB Output is correct
6 Correct 88 ms 17720 KB Output is correct
7 Correct 66 ms 17784 KB Output is correct
8 Correct 81 ms 17724 KB Output is correct
9 Correct 101 ms 17720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 31 ms 5788 KB Output is correct
3 Correct 76 ms 9904 KB Output is correct
4 Correct 78 ms 11316 KB Output is correct
5 Correct 116 ms 11320 KB Output is correct
6 Correct 76 ms 11312 KB Output is correct
7 Correct 101 ms 11332 KB Output is correct
8 Correct 102 ms 11276 KB Output is correct
9 Correct 96 ms 11328 KB Output is correct
10 Correct 97 ms 11212 KB Output is correct
11 Correct 100 ms 12176 KB Output is correct
12 Correct 108 ms 13328 KB Output is correct
13 Correct 132 ms 12852 KB Output is correct
14 Correct 114 ms 13304 KB Output is correct
15 Correct 100 ms 11304 KB Output is correct
16 Correct 85 ms 11332 KB Output is correct
17 Correct 104 ms 12472 KB Output is correct
18 Correct 98 ms 13028 KB Output is correct
19 Correct 91 ms 11312 KB Output is correct
20 Correct 139 ms 13752 KB Output is correct
21 Correct 86 ms 11500 KB Output is correct
22 Correct 75 ms 11500 KB Output is correct
23 Correct 95 ms 11508 KB Output is correct
24 Correct 87 ms 12144 KB Output is correct
25 Correct 86 ms 17080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 6056 KB Output is correct
2 Correct 11 ms 6224 KB Output is correct
3 Correct 130 ms 15356 KB Output is correct
4 Correct 115 ms 15972 KB Output is correct
5 Correct 127 ms 17284 KB Output is correct
6 Correct 155 ms 17364 KB Output is correct
7 Correct 192 ms 17196 KB Output is correct
8 Correct 166 ms 17212 KB Output is correct
9 Correct 128 ms 13748 KB Output is correct
10 Correct 113 ms 14220 KB Output is correct
11 Correct 100 ms 15012 KB Output is correct
12 Correct 130 ms 16260 KB Output is correct
13 Correct 152 ms 16756 KB Output is correct
14 Correct 142 ms 17192 KB Output is correct
15 Correct 151 ms 17308 KB Output is correct
16 Correct 113 ms 15060 KB Output is correct
17 Correct 106 ms 15348 KB Output is correct
18 Correct 84 ms 15492 KB Output is correct
19 Correct 102 ms 15448 KB Output is correct
20 Correct 87 ms 15600 KB Output is correct
21 Correct 123 ms 17168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6096 KB Output is correct
2 Correct 13 ms 6248 KB Output is correct
3 Correct 140 ms 15516 KB Output is correct
4 Incorrect 98 ms 15636 KB Output is incorrect: {s, t} is wrong.
5 Halted 0 ms 0 KB -