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;
int a,b,c,d,e,i,j,ii,jj,zx,xc,A,B,msh[100009],dep[100009],lef,rig,mid,E,DEP,C,D;
long long K,KK,X;
vector <pair <int, int> > v[100009];
vector <int> vv,de[100009];
long long ask(const std::vector<int> &w);
void answer(int s, int t);
void dfs(int q, int w){
dep[q]=dep[w]+1;
de[dep[q]].push_back(q);
DEP=max(DEP,dep[q]);
for(vector <pair <int, int> >::iterator it=v[q].begin(); it!=v[q].end(); it++){
if((*it).first==w) continue;
msh[(*it).first]=(*it).second;
dfs((*it).first,q);
}
}
int fun(){
lef=0;rig=de[E].size()-1;
while(1){
if(lef==rig) return de[E][lef];
mid=(lef+rig)/2;
for(i=0; i<b; i++){
vv[i]=0;
}
for(i=lef; i<=mid; i++){
vv[msh[de[E][i]]]=1;
}
X=ask(vv);
if(K==X){
lef=mid+1;
}else{
rig=mid;
}
}
}
void find_pair(int N, vector<int> U, vector<int> V, int AA, int BB) {
A=AA;B=BB;
a=N;b=U.size();
for(i=0; i<U.size(); i++){
U[i]++;
V[i]++;
v[U[i]].push_back(make_pair(V[i],i));
v[V[i]].push_back(make_pair(U[i],i));
}
vv.resize(b);
for(i=0; i<b; i++){
vv[i]=0;
}
K=ask(vv);X=A;
KK=K/X;
DEP=0;
dfs(1,0);
lef=1;rig=DEP+1;
while(1){
if(lef+1>=rig) break;
mid=(lef+rig)/2;
for(i=1; i<=a; i++){
if(i==1) continue;
if(dep[i]>=mid){
vv[msh[i]]=1;
}else{
vv[msh[i]]=0;
}
}
X=ask(vv);
if(K==X){
rig=mid;
}else{
lef=mid;
}
}
E=lef;
C=fun();
//answer(C-1,D-1);
for(i=0; i<=a+1; i++){
de[i].clear();
dep[i]=0;msh[i]=0;
}
DEP=0;
dfs(C,0);
E=KK+1;
D=fun();
answer(C-1,D-1);
}
/*
namespace {
int MAX_NUM_CALLS = 100;
long long INF = 1LL << 61;
int N, M, A, B, S, T;
std::vector<int> U, V;
std::vector<std::vector<std::pair<int, int> > > graph;
bool answered, wrong_pair;
int num_calls;
int read_int() {
int x;
if (scanf("%d", &x) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
return x;
}
void wrong_answer(const char *MSG) {
printf("Wrong Answer: %s\n", MSG);
exit(0);
}
} // namespace
long long ask(const std::vector<int> &w) {
if (++num_calls > MAX_NUM_CALLS) {
wrong_answer("more than 100 calls to ask");
}
if (w.size() != (size_t)M) {
wrong_answer("w is invalid");
}
for (size_t i = 0; i < w.size(); ++i) {
if (!(w[i] == 0 || w[i] == 1)) {
wrong_answer("w is invalid");
}
}
std::vector<bool> visited(N, false);
std::vector<long long> current_dist(N, INF);
std::queue<int> qa, qb;
qa.push(S);
current_dist[S] = 0;
while (!qa.empty() || !qb.empty()) {
int v;
if (qb.empty() ||
(!qa.empty() && current_dist[qa.front()] <= current_dist[qb.front()])) {
v = qa.front();
qa.pop();
} else {
v = qb.front();
qb.pop();
}
if (visited[v]) {
continue;
}
visited[v] = true;
long long d = current_dist[v];
if (v == T) {
return d;
}
for (vector <pair <int, int> >::iterator ee=graph[v].begin(); ee!=graph[v].end(); ee++) {
int vv = (*ee).first;
int ei = (*ee).second;
if (!visited[vv]) {
if (w[ei] == 0) {
if (current_dist[vv] > d + A) {
current_dist[vv] = d + A;
qa.push(vv);
}
} else {
if (current_dist[vv] > d + B) {
current_dist[vv] = d + B;
qb.push(vv);
}
}
}
}
}
return -1;
}
void answer(int s, int t) {
if (answered) {
wrong_answer("answered not exactly once");
}
if (!((s == S && t == T) || (s == T && t == S))) {
wrong_pair = true;
}
answered = true;
}
int main() {
N = read_int();
M = read_int();
A = read_int();
B = read_int();
S = read_int();
T = read_int();
U.resize(M);
V.resize(M);
graph.assign(N, std::vector<std::pair<int, int>>());
for (int i = 0; i < M; ++i) {
U[i] = read_int();
V[i] = read_int();
graph[U[i]].push_back({V[i], i});
graph[V[i]].push_back({U[i], i});
}
answered = false;
wrong_pair = false;
num_calls = 0;
find_pair(N, U, V, A, B);
if (!answered) {
wrong_answer("answered not exactly once");
}
if (wrong_pair) {
wrong_answer("{s, t} is wrong");
}
printf("Accepted: %d\n", num_calls);
return 0;
}
*/
Compilation message (stderr)
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:42:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(i=0; i<U.size(); i++){
| ~^~~~~~~~~
# | 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... |