#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
/*
int N,M,A,B,S,T;
vector<int> U,V;
vector<vector<pair<int,int> > > NG;
long long int ask(vector<int> W){
queue<pair<long long int,int> > q;
q.push({0,S});
vector<long long int> dst(N,1e16);
dst[S]=0;
while(q.size()){
pair<int,int> cur=q.front();
long long int d=-cur.first;
long long int nd=cur.second;
q.pop();
for(int i = 0 ; i < NG[nd].size() ; i ++){
int ne=NG[nd][i].first;
int ew=NG[nd][i].second;
ew=W[ew]*(B-A)+A;
if(d+ew<dst[ne]){
dst[ne]=d+ew;
q.push({-dst[ne],ne});
}
}
}
return dst[T];
}
void answer(int A,int B){
if(min(A,B)!=min(S,T)||max(A,B)!=max(S,T))cout<<"WONG"<<endl;
cout<<S<<" "<<T<<" "<<A<<" "<<B<<endl;
}
*/
int n,m,a,b,s,t;
long long int minpr,maxpr,tmp;
vector<int> u,v,w;
vector<vector<pair<int,int> > > ng;
vector<vector<int> > bfs(int st,int ed){
vector<vector<int> > rz(n,{n+1,0,0});
rz[st]={0,ed,st};
priority_queue<vector<int> > q;
q.push({rz[st]});
while(q.size()){
vector<int> cr=q.top();
q.pop();
int cn=cr[2];
int cd=-cr[0];
for(int i = 0 ; i < ng[cn].size() ; i ++ ){
int ne=ng[cn][i].first;
int en=ng[cn][i].second;
if(rz[ne][0]>cd+1){
rz[ne]={-cd-1,en,ne};
q.push(rz[ne]);
rz[ne][0]*=-1;
}
}
}
return rz;
}
int fnd(vector<vector<int> > s0,vector<vector<int> > s3){
int l=0,r=s0.size();
while(l!=r-1){
int md=(l+r)/2;
w.clear();
w.resize(m,1);
for(int i = 0 ; i < s3.size() ; i ++)
w[s3[i][1]]=0;
w[s0[0][1]]=1;
for(int i = 0 ; i < md ; i ++)
w[s0[i][1]]=0;
tmp=ask(w);
if(tmp==minpr){
r=md;
}else{
l=md;
}
}
return s0[l][2];
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
u=U;v=V;n=N;
m=u.size();
ng.clear();
ng.resize(n);
for(int i = 0 ; i < m ; i ++){
ng[u[i]].push_back({v[i],i});
ng[v[i]].push_back({u[i],i});
}
w.clear();
w.resize(m);
minpr=ask(w);
maxpr=minpr/A*B;
int l=0,r=m;
while(l!=r-1){
int md=(l+r)/2;
for(int i = 0 ; i < m ; i ++){
if(i<md)
w[i]=1;
else
w[i]=0;
}
tmp=ask(w);
if(tmp==minpr){
l=md;
}else{
r=md;
}
}
// cout<<l<<" "<<u[l]<<" "<<v[l]<<endl<<endl;
vector<vector<int> > g1=bfs(u[l],l);
vector<vector<int> > g2=bfs(v[l],l);
vector<vector<int> > s1,s2;
for(int i = 0 ; i < n ; i ++){
if(g1[i][0]<g2[i][0]){
s1.push_back(g1[i]);
}else if(g2[i][0]<g1[i][0]){
s2.push_back(g2[i]);
}
}
sort(s1.begin(),s1.end());
sort(s2.begin(),s2.end());
// for(int i = 0 ; i < s1.size() ; i ++){
// cout<<s1[i][0]<<" "<<s1[i][1]<<" "<<s1[i][2]<<endl;
// }
// cout<<endl;
t=fnd(s1,s2);
// cout<<endl;
// cout<<endl;
// for(int i = 0 ; i < s2.size() ; i ++){
// cout<<s2[i][0]<<" "<<s2[i][1]<<" "<<s2[i][2]<<endl;
// }
// cout<<endl;
// cout<<endl;
s=fnd(s2,s1);
answer(s,t);
}
//int main(){
// cin>>N>>M>>A>>B>>S>>T;
// U.resize(M);
// V.resize(M);
// NG.resize(N);
// for(int i = 0 ; i < M ; i ++){
// cin>>U[i]>>V[i];
// NG[U[i]].push_back({V[i],i});
// NG[V[i]].push_back({U[i],i});
// }
// cout<<"EVEIL"<<endl;
// find_pair(N,U,V,A,B);
// /*for(S = 0 ; S < N ; S ++){
// for(T = 0 ; T < N ; T ++){
// if(S==T)continue;
// find_pair(N,U,V,A,B);
//
// }
// }*/
//}
/**
14 22 14862 18232 6 10
0 1 0 4 0 13 0 9 0 10
1 13 1 2 1 4
2 3 2 5 2 6
3 6 3 7
4 5 4 8
5 8 5 9
8 10 8 12
9 12
10 11
11 12
**/
/**
10 9 2 3 4 8
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
**/
/**
10 10 2 3 0 5
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 0
**/
Compilation message
highway.cpp: In function 'std::vector<std::vector<int> > bfs(int, int)':
highway.cpp:52:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ; i < ng[cn].size() ; i ++ ){
~~^~~~~~~~~~~~~~~
highway.cpp: In function 'int fnd(std::vector<std::vector<int> >, std::vector<std::vector<int> >)':
highway.cpp:70:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ; i < s3.size() ; i ++)
~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
404 KB |
Output is correct |
2 |
Correct |
2 ms |
324 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
408 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
248 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
248 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
324 KB |
Output is correct |
12 |
Correct |
2 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
32 ms |
3420 KB |
Output is correct |
3 |
Correct |
428 ms |
28076 KB |
Output is correct |
4 |
Correct |
436 ms |
28052 KB |
Output is correct |
5 |
Correct |
447 ms |
28032 KB |
Output is correct |
6 |
Correct |
424 ms |
28032 KB |
Output is correct |
7 |
Correct |
448 ms |
28128 KB |
Output is correct |
8 |
Correct |
426 ms |
28040 KB |
Output is correct |
9 |
Correct |
454 ms |
28036 KB |
Output is correct |
10 |
Correct |
418 ms |
28148 KB |
Output is correct |
11 |
Correct |
381 ms |
27580 KB |
Output is correct |
12 |
Correct |
377 ms |
27524 KB |
Output is correct |
13 |
Correct |
358 ms |
27584 KB |
Output is correct |
14 |
Correct |
378 ms |
27480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
3312 KB |
Output is correct |
2 |
Correct |
54 ms |
6400 KB |
Output is correct |
3 |
Correct |
82 ms |
9500 KB |
Output is correct |
4 |
Correct |
245 ms |
27596 KB |
Output is correct |
5 |
Correct |
223 ms |
27500 KB |
Output is correct |
6 |
Correct |
251 ms |
27472 KB |
Output is correct |
7 |
Correct |
242 ms |
27496 KB |
Output is correct |
8 |
Correct |
264 ms |
27492 KB |
Output is correct |
9 |
Correct |
248 ms |
27580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
616 KB |
Output is correct |
2 |
Correct |
40 ms |
3320 KB |
Output is correct |
3 |
Correct |
305 ms |
21916 KB |
Output is correct |
4 |
Correct |
466 ms |
28044 KB |
Output is correct |
5 |
Correct |
411 ms |
28152 KB |
Output is correct |
6 |
Correct |
414 ms |
28028 KB |
Output is correct |
7 |
Correct |
408 ms |
28036 KB |
Output is correct |
8 |
Correct |
402 ms |
27992 KB |
Output is correct |
9 |
Correct |
437 ms |
28036 KB |
Output is correct |
10 |
Correct |
436 ms |
28048 KB |
Output is correct |
11 |
Correct |
371 ms |
27492 KB |
Output is correct |
12 |
Correct |
377 ms |
27576 KB |
Output is correct |
13 |
Correct |
370 ms |
27588 KB |
Output is correct |
14 |
Correct |
395 ms |
27604 KB |
Output is correct |
15 |
Correct |
421 ms |
28036 KB |
Output is correct |
16 |
Correct |
410 ms |
28060 KB |
Output is correct |
17 |
Correct |
411 ms |
27484 KB |
Output is correct |
18 |
Correct |
345 ms |
27496 KB |
Output is correct |
19 |
Correct |
408 ms |
28116 KB |
Output is correct |
20 |
Correct |
360 ms |
27592 KB |
Output is correct |
21 |
Correct |
365 ms |
28232 KB |
Output is correct |
22 |
Correct |
377 ms |
28180 KB |
Output is correct |
23 |
Correct |
373 ms |
28184 KB |
Output is correct |
24 |
Correct |
384 ms |
28236 KB |
Output is correct |
25 |
Correct |
386 ms |
27588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
3344 KB |
Output is correct |
2 |
Correct |
34 ms |
3384 KB |
Output is correct |
3 |
Correct |
529 ms |
28192 KB |
Output is correct |
4 |
Correct |
470 ms |
27396 KB |
Output is correct |
5 |
Correct |
516 ms |
28640 KB |
Output is correct |
6 |
Correct |
533 ms |
28296 KB |
Output is correct |
7 |
Correct |
548 ms |
27536 KB |
Output is correct |
8 |
Correct |
550 ms |
27532 KB |
Output is correct |
9 |
Correct |
314 ms |
14456 KB |
Output is correct |
10 |
Correct |
238 ms |
13416 KB |
Output is correct |
11 |
Correct |
336 ms |
17648 KB |
Output is correct |
12 |
Correct |
436 ms |
22340 KB |
Output is correct |
13 |
Correct |
497 ms |
24976 KB |
Output is correct |
14 |
Correct |
557 ms |
27968 KB |
Output is correct |
15 |
Correct |
508 ms |
28532 KB |
Output is correct |
16 |
Correct |
335 ms |
15396 KB |
Output is correct |
17 |
Correct |
383 ms |
28372 KB |
Output is correct |
18 |
Correct |
386 ms |
28544 KB |
Output is correct |
19 |
Correct |
423 ms |
28360 KB |
Output is correct |
20 |
Correct |
383 ms |
28476 KB |
Output is correct |
21 |
Correct |
453 ms |
29852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
3356 KB |
Output is correct |
2 |
Correct |
44 ms |
3400 KB |
Output is correct |
3 |
Correct |
467 ms |
27140 KB |
Output is correct |
4 |
Correct |
484 ms |
27116 KB |
Output is correct |
5 |
Correct |
504 ms |
27512 KB |
Output is correct |
6 |
Correct |
543 ms |
27376 KB |
Output is correct |
7 |
Correct |
463 ms |
28528 KB |
Output is correct |
8 |
Correct |
502 ms |
28048 KB |
Output is correct |
9 |
Correct |
497 ms |
26768 KB |
Output is correct |
10 |
Correct |
541 ms |
27576 KB |
Output is correct |
11 |
Correct |
533 ms |
27368 KB |
Output is correct |
12 |
Correct |
540 ms |
27372 KB |
Output is correct |
13 |
Correct |
346 ms |
17660 KB |
Output is correct |
14 |
Correct |
310 ms |
13672 KB |
Output is correct |
15 |
Correct |
339 ms |
17632 KB |
Output is correct |
16 |
Correct |
282 ms |
13400 KB |
Output is correct |
17 |
Correct |
319 ms |
17680 KB |
Output is correct |
18 |
Correct |
310 ms |
13444 KB |
Output is correct |
19 |
Correct |
480 ms |
22716 KB |
Output is correct |
20 |
Correct |
519 ms |
25912 KB |
Output is correct |
21 |
Correct |
558 ms |
27868 KB |
Output is correct |
22 |
Correct |
501 ms |
27672 KB |
Output is correct |
23 |
Correct |
547 ms |
27780 KB |
Output is correct |
24 |
Correct |
556 ms |
27856 KB |
Output is correct |
25 |
Correct |
550 ms |
28076 KB |
Output is correct |
26 |
Correct |
515 ms |
27972 KB |
Output is correct |
27 |
Correct |
395 ms |
28564 KB |
Output is correct |
28 |
Correct |
375 ms |
28412 KB |
Output is correct |
29 |
Correct |
396 ms |
28668 KB |
Output is correct |
30 |
Correct |
412 ms |
28440 KB |
Output is correct |
31 |
Correct |
405 ms |
28496 KB |
Output is correct |
32 |
Correct |
381 ms |
28288 KB |
Output is correct |
33 |
Correct |
398 ms |
28728 KB |
Output is correct |
34 |
Correct |
411 ms |
28352 KB |
Output is correct |
35 |
Correct |
388 ms |
28352 KB |
Output is correct |
36 |
Correct |
396 ms |
28484 KB |
Output is correct |
37 |
Correct |
373 ms |
28624 KB |
Output is correct |
38 |
Correct |
377 ms |
28476 KB |
Output is correct |
39 |
Correct |
447 ms |
29800 KB |
Output is correct |
40 |
Correct |
459 ms |
29788 KB |
Output is correct |
41 |
Correct |
515 ms |
29636 KB |
Output is correct |
42 |
Correct |
467 ms |
29788 KB |
Output is correct |