# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
158160 | kig9981 | Highway Tolls (IOI18_highway) | C++17 | 259 ms | 18120 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[90000];
set<int> gv[90000];
int g[90000];
void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{
int M=U.size(), sg=0, tg=0, gnum=0;
vector<int> W(M);
long long dist=ask(W);
for(int i=0;i<M;i++) {
adj[U[i]].push_back(V[i]);
adj[V[i]].push_back(U[i]);
}
for(int i=0;i<N;i++) gv[0].insert(i);
while(gv[sg].size()>1) {
++gnum;
for(auto c: gv[sg]) {
gv[gnum].insert(c);
g[c]=gnum;
if(2*gv[gnum].size()>=gv[sg].size()) break;
}
for(auto c: gv[gnum]) gv[sg].erase(c);
if(gv[gnum].size()==1) {
for(int i=0;i<M;i++) W[i]=g[U[i]]==gnum || g[V[i]]==gnum;
if(ask(W)==dist+B-A) sg=gnum;
}
else {
long long temp;
for(int i=0;i<M;i++) W[i]=g[U[i]]==gnum && g[V[i]]!=gnum || g[U[i]]!=gnum && g[V[i]]==gnum;
temp=(ask(W)-dist)/(B-A);
if(sg==tg) {
if(temp&1) sg=gnum;
else if(temp) sg=tg=gnum;
}
else if(temp&1) sg=gnum;
}
}
while(gv[tg].size()>1) {
++gnum;
for(auto c: gv[tg]) {
gv[gnum].insert(c);
g[c]=gnum;
if(2*gv[gnum].size()>=gv[tg].size()) break;
}
for(auto c: gv[gnum]) gv[tg].erase(c);
if(gv[gnum].size()==1) {
for(int i=0;i<M;i++) W[i]=g[U[i]]==gnum || g[V[i]]==gnum;
if(ask(W)==dist+B-A) tg=gnum;
}
else {
for(int i=0;i<M;i++) W[i]=g[U[i]]==gnum && g[V[i]]!=gnum || g[U[i]]!=gnum && g[V[i]]==gnum;
if((ask(W)-dist)/(B-A)&1) tg=gnum;
}
}
answer(*gv[sg].begin(),*gv[tg].begin());
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |