#include "highway.h"
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
vector <pair <int,int> > g[90000]; //first: connection to which node, second: edge no.
long long dist;
vector <pair <int,int> > poss;
void dfs(int cur,int prev,int d){
for (auto&i:g[cur]){
if (i.x==prev) continue;
if (d+1==dist) poss.push_back({i.y,i.x});
else dfs(i.x,cur,d+1);
}
}
void find_pair(int n,vector <int> u,vector <int> v,int A,int b){
long long a=A;
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> query(m,0);
dist=ask(query);
dist/=a;
bool can=1;
for (int i=0; i<m; i++){
if (u[i]!=i||v[i]!=i+1){
can=0;
break;
}
}
if (can){ //subtask 3
vector <int> possible;
for (int i=0; i<n; i++) possible.push_back(i);
while (possible.size()>1){
vector <int> f,s;
for (int i=0; i<possible.size(); i++){
if (i<(possible.size()/2)) f.push_back(possible[i]);
else s.push_back(possible[i]);
}
vector <int> query(m,0);
for (auto&i:f) query[i]=1;
if (ask(query)==dist*a) possible=s;
else possible=f;
}
answer(possible[0],possible[0]+dist);
} else {
dfs(0,-1,0);
while (poss.size()>1){
vector <pair <int,int> > f,s;
for (int i=0; i<poss.size(); i++){
if (i<(poss.size()/2)) f.push_back(poss[i]);
else s.push_back(poss[i]);
}
vector <int> query(m,0);
for (auto&i:f) query[i.x]=1;
if (ask(query)==dist*a) poss=s;
else poss=f;
}
answer(0,poss[0].y);
}
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int i=0; i<possible.size(); i++){
| ~^~~~~~~~~~~~~~~~
highway.cpp:39:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if (i<(possible.size()/2)) f.push_back(possible[i]);
| ~^~~~~~~~~~~~~~~~~~~~
highway.cpp:52:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i=0; i<poss.size(); i++){
| ~^~~~~~~~~~~~
highway.cpp:53:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | if (i<(poss.size()/2)) f.push_back(poss[i]);
| ~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2412 KB |
Output is correct |
2 |
Correct |
2 ms |
2412 KB |
Output is correct |
3 |
Correct |
2 ms |
2496 KB |
Output is correct |
4 |
Correct |
2 ms |
2412 KB |
Output is correct |
5 |
Correct |
2 ms |
2432 KB |
Output is correct |
6 |
Correct |
2 ms |
2412 KB |
Output is correct |
7 |
Correct |
2 ms |
2412 KB |
Output is correct |
8 |
Correct |
2 ms |
2412 KB |
Output is correct |
9 |
Correct |
2 ms |
2496 KB |
Output is correct |
10 |
Correct |
2 ms |
2496 KB |
Output is correct |
11 |
Correct |
2 ms |
2412 KB |
Output is correct |
12 |
Correct |
2 ms |
2412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2540 KB |
Output is correct |
2 |
Correct |
14 ms |
3052 KB |
Output is correct |
3 |
Correct |
123 ms |
8300 KB |
Output is correct |
4 |
Correct |
114 ms |
8296 KB |
Output is correct |
5 |
Correct |
127 ms |
8308 KB |
Output is correct |
6 |
Correct |
120 ms |
8044 KB |
Output is correct |
7 |
Correct |
117 ms |
8072 KB |
Output is correct |
8 |
Correct |
126 ms |
8292 KB |
Output is correct |
9 |
Correct |
117 ms |
7944 KB |
Output is correct |
10 |
Correct |
122 ms |
8296 KB |
Output is correct |
11 |
Correct |
114 ms |
7692 KB |
Output is correct |
12 |
Correct |
116 ms |
8076 KB |
Output is correct |
13 |
Correct |
118 ms |
8076 KB |
Output is correct |
14 |
Correct |
114 ms |
8332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
3180 KB |
Output is correct |
2 |
Correct |
24 ms |
3820 KB |
Output is correct |
3 |
Correct |
35 ms |
4332 KB |
Output is correct |
4 |
Correct |
91 ms |
8420 KB |
Output is correct |
5 |
Correct |
106 ms |
8548 KB |
Output is correct |
6 |
Correct |
109 ms |
8292 KB |
Output is correct |
7 |
Correct |
100 ms |
8300 KB |
Output is correct |
8 |
Correct |
107 ms |
8292 KB |
Output is correct |
9 |
Correct |
108 ms |
8292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2540 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
4704 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
3180 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |