//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
#define ask count_common_roads
#include "simurgh.h"
int par[501];
vector<pair<int,int>> adj[501];
int find(int no){
if(par[no]==no){
return no;
}
par[no]=find(par[no]);
return par[no];
}
int ca=-1;
vector<int> pp;
vector<int> pp2;
void dfs(int no,int par2=-1){
if(no==ca){
pp2=pp;
}
for(auto j:adj[no]){
if(j.a!=par2){
pp.pb(j.b);
dfs(j.a,no);
pp.pop_back();
}
}
}
vector<int> find_roads(int n,vector<int> uu,vector<int> vv) {
int m=uu.size();
for(int i=0;i<n;i++){
par[i]=i;
}
vector<pair<pair<int,int>,int>> cur;
vector<pair<pair<int,int>,int>> cur2;
for(int i=0;i<m;i++){
int x=find(uu[i]);
int y=find(vv[i]);
if(x!=y){
par[x]=y;
cur.pb({{uu[i],vv[i]},i});
adj[uu[i]].pb({vv[i],i});
adj[vv[i]].pb({uu[i],i});
}
else{
cur2.pb({{uu[i],vv[i]},i});
}
}
//mt19937 rng;
//rng=mt19937(chrono::steady_clock::now().time_since_epoch().count());
int val;
vector<int> ee;
for(auto j:cur){
ee.pb(j.b);
}
val=ask(ee);
vector<int> ans;
for(int i=0;i<m;i++){
ans.pb(0);
}
for(auto j:cur2){
ca=j.a.b;
dfs(j.a.a);
int cur=-1;
for(auto i:pp2){
if(ans[i]!=0){
cur=i;
}
}
/* for(auto i:pp2){
cout<<i<<",";
}
cout<<endl;*/
if(cur==-1){
vector<pair<int,int>> xx;
xx.pb({val,j.b});
for(auto i:pp2){
vector<int> ff;
for(auto jj:ee){
if(jj!=i){
ff.pb(jj);
}
}
ff.pb(j.b);
int val2=ask(ff);
xx.pb({val2,i});
}
sort(xx.begin(),xx.end());
for(int i=0;i<xx.size();i++){
if(xx[i].a==xx.back().a-1){
ans[xx[i].b]=1;
}
else{
ans[xx[i].b]=-1;
}
}
/*for(auto j:xx){
cout<<j.a<<"::"<<j.b<<endl;
}
cout<<endl;*/
}
else{
if(true){
vector<int> ff;
for(auto jj:ee){
if(jj!=cur){
ff.pb(jj);
}
}
ff.pb(j.b);
int val2=ask(ff);
int xx=val;
if(ans[cur]==1){
xx--;
}
if(val2==xx){
ans[j.b]=-1;
}
else{
ans[j.b]=1;
}
}
for(auto i:pp2){
if(ans[i]!=0){
continue;
}
vector<int> ff;
for(auto jj:ee){
if(jj!=i){
ff.pb(jj);
}
}
ff.pb(j.b);
int val2=ask(ff);
int xx=val;
if(ans[j.b]==1){
xx+=1;
}
if(val2==xx){
ans[i]=-1;
}
else{
ans[i]=1;
}
}
}
/* for(auto i:ans){
cout<<i<<".";
}
cout<<endl;*/
}
vector<int> ans2;
for(int i=0;i<m;i++){
if(ans[i]==1 or ans[i]==0){
ans2.pb(i);
}
}
// for(int i=0;i<m;i++){
// cout<<ans[i]<<":";
// }
// cout<<endl;
return ans2;
/* shuffle(cur2.begin(),cur2.end(),rng);
for(auto j:cur2){
if(val==n-1){
break;
}
for(int i=0;i<n;i++){
adj[i].clear();
}
for(auto i:cur){
adj[i.a.a].pb({i.a.b,i.b});
adj[i.a.b].pb({i.a.a,i.b});
}
ca=j.a.b;
dfs(j.a.a);
shuffle(pp2.begin(),pp2.end(),rng);
for(auto i:pp2){
vector<int> ff;
for(auto jj:ee){
if(jj!=i){
ff.pb(jj);
}
}
ff.pb(j.b);
int val2=ask(ff);
if(val2<val){
break;
}
if(val2==val){
continue;
}
vector<pair<pair<int,int>,int>> cur3;
for(auto ii:cur){
if(ii.b==i){
continue;
}
cur3.pb(ii);
}
cur3.pb(j);
cur=cur3;
val=val2;
ee=ff;
break;
}
}*/
// return ee;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:99:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | for(int i=0;i<xx.size();i++){
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Correct |
1 ms |
204 KB |
correct |
4 |
Correct |
1 ms |
308 KB |
correct |
5 |
Correct |
1 ms |
204 KB |
correct |
6 |
Correct |
1 ms |
312 KB |
correct |
7 |
Correct |
1 ms |
208 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
1 ms |
204 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
1 ms |
204 KB |
correct |
13 |
Correct |
1 ms |
204 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Correct |
1 ms |
204 KB |
correct |
4 |
Correct |
1 ms |
308 KB |
correct |
5 |
Correct |
1 ms |
204 KB |
correct |
6 |
Correct |
1 ms |
312 KB |
correct |
7 |
Correct |
1 ms |
208 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
1 ms |
204 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
1 ms |
204 KB |
correct |
13 |
Correct |
1 ms |
204 KB |
correct |
14 |
Correct |
4 ms |
332 KB |
correct |
15 |
Correct |
4 ms |
332 KB |
correct |
16 |
Correct |
4 ms |
336 KB |
correct |
17 |
Correct |
3 ms |
332 KB |
correct |
18 |
Correct |
2 ms |
332 KB |
correct |
19 |
Correct |
3 ms |
332 KB |
correct |
20 |
Correct |
4 ms |
332 KB |
correct |
21 |
Correct |
3 ms |
312 KB |
correct |
22 |
Correct |
4 ms |
332 KB |
correct |
23 |
Correct |
3 ms |
336 KB |
correct |
24 |
Correct |
2 ms |
308 KB |
correct |
25 |
Correct |
1 ms |
204 KB |
correct |
26 |
Correct |
3 ms |
332 KB |
correct |
27 |
Correct |
2 ms |
316 KB |
correct |
28 |
Correct |
1 ms |
204 KB |
correct |
29 |
Correct |
1 ms |
208 KB |
correct |
30 |
Correct |
2 ms |
332 KB |
correct |
31 |
Correct |
2 ms |
332 KB |
correct |
32 |
Correct |
2 ms |
332 KB |
correct |
33 |
Correct |
2 ms |
332 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Correct |
1 ms |
204 KB |
correct |
4 |
Correct |
1 ms |
308 KB |
correct |
5 |
Correct |
1 ms |
204 KB |
correct |
6 |
Correct |
1 ms |
312 KB |
correct |
7 |
Correct |
1 ms |
208 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
1 ms |
204 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
1 ms |
204 KB |
correct |
13 |
Correct |
1 ms |
204 KB |
correct |
14 |
Correct |
4 ms |
332 KB |
correct |
15 |
Correct |
4 ms |
332 KB |
correct |
16 |
Correct |
4 ms |
336 KB |
correct |
17 |
Correct |
3 ms |
332 KB |
correct |
18 |
Correct |
2 ms |
332 KB |
correct |
19 |
Correct |
3 ms |
332 KB |
correct |
20 |
Correct |
4 ms |
332 KB |
correct |
21 |
Correct |
3 ms |
312 KB |
correct |
22 |
Correct |
4 ms |
332 KB |
correct |
23 |
Correct |
3 ms |
336 KB |
correct |
24 |
Correct |
2 ms |
308 KB |
correct |
25 |
Correct |
1 ms |
204 KB |
correct |
26 |
Correct |
3 ms |
332 KB |
correct |
27 |
Correct |
2 ms |
316 KB |
correct |
28 |
Correct |
1 ms |
204 KB |
correct |
29 |
Correct |
1 ms |
208 KB |
correct |
30 |
Correct |
2 ms |
332 KB |
correct |
31 |
Correct |
2 ms |
332 KB |
correct |
32 |
Correct |
2 ms |
332 KB |
correct |
33 |
Correct |
2 ms |
332 KB |
correct |
34 |
Correct |
295 ms |
1560 KB |
correct |
35 |
Correct |
287 ms |
1604 KB |
correct |
36 |
Correct |
197 ms |
1164 KB |
correct |
37 |
Correct |
15 ms |
332 KB |
correct |
38 |
Correct |
295 ms |
1448 KB |
correct |
39 |
Correct |
266 ms |
1388 KB |
correct |
40 |
Correct |
195 ms |
1164 KB |
correct |
41 |
Correct |
297 ms |
1472 KB |
correct |
42 |
Correct |
294 ms |
1488 KB |
correct |
43 |
Correct |
148 ms |
964 KB |
correct |
44 |
Correct |
120 ms |
844 KB |
correct |
45 |
Correct |
151 ms |
912 KB |
correct |
46 |
Correct |
108 ms |
844 KB |
correct |
47 |
Correct |
42 ms |
560 KB |
correct |
48 |
Correct |
3 ms |
332 KB |
correct |
49 |
Correct |
12 ms |
400 KB |
correct |
50 |
Correct |
45 ms |
564 KB |
correct |
51 |
Correct |
142 ms |
888 KB |
correct |
52 |
Correct |
122 ms |
872 KB |
correct |
53 |
Correct |
112 ms |
844 KB |
correct |
54 |
Correct |
155 ms |
968 KB |
correct |
55 |
Correct |
137 ms |
908 KB |
correct |
56 |
Correct |
132 ms |
952 KB |
correct |
57 |
Correct |
130 ms |
944 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Incorrect |
242 ms |
3940 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Correct |
1 ms |
204 KB |
correct |
4 |
Correct |
1 ms |
308 KB |
correct |
5 |
Correct |
1 ms |
204 KB |
correct |
6 |
Correct |
1 ms |
312 KB |
correct |
7 |
Correct |
1 ms |
208 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
1 ms |
204 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
1 ms |
204 KB |
correct |
13 |
Correct |
1 ms |
204 KB |
correct |
14 |
Correct |
4 ms |
332 KB |
correct |
15 |
Correct |
4 ms |
332 KB |
correct |
16 |
Correct |
4 ms |
336 KB |
correct |
17 |
Correct |
3 ms |
332 KB |
correct |
18 |
Correct |
2 ms |
332 KB |
correct |
19 |
Correct |
3 ms |
332 KB |
correct |
20 |
Correct |
4 ms |
332 KB |
correct |
21 |
Correct |
3 ms |
312 KB |
correct |
22 |
Correct |
4 ms |
332 KB |
correct |
23 |
Correct |
3 ms |
336 KB |
correct |
24 |
Correct |
2 ms |
308 KB |
correct |
25 |
Correct |
1 ms |
204 KB |
correct |
26 |
Correct |
3 ms |
332 KB |
correct |
27 |
Correct |
2 ms |
316 KB |
correct |
28 |
Correct |
1 ms |
204 KB |
correct |
29 |
Correct |
1 ms |
208 KB |
correct |
30 |
Correct |
2 ms |
332 KB |
correct |
31 |
Correct |
2 ms |
332 KB |
correct |
32 |
Correct |
2 ms |
332 KB |
correct |
33 |
Correct |
2 ms |
332 KB |
correct |
34 |
Correct |
295 ms |
1560 KB |
correct |
35 |
Correct |
287 ms |
1604 KB |
correct |
36 |
Correct |
197 ms |
1164 KB |
correct |
37 |
Correct |
15 ms |
332 KB |
correct |
38 |
Correct |
295 ms |
1448 KB |
correct |
39 |
Correct |
266 ms |
1388 KB |
correct |
40 |
Correct |
195 ms |
1164 KB |
correct |
41 |
Correct |
297 ms |
1472 KB |
correct |
42 |
Correct |
294 ms |
1488 KB |
correct |
43 |
Correct |
148 ms |
964 KB |
correct |
44 |
Correct |
120 ms |
844 KB |
correct |
45 |
Correct |
151 ms |
912 KB |
correct |
46 |
Correct |
108 ms |
844 KB |
correct |
47 |
Correct |
42 ms |
560 KB |
correct |
48 |
Correct |
3 ms |
332 KB |
correct |
49 |
Correct |
12 ms |
400 KB |
correct |
50 |
Correct |
45 ms |
564 KB |
correct |
51 |
Correct |
142 ms |
888 KB |
correct |
52 |
Correct |
122 ms |
872 KB |
correct |
53 |
Correct |
112 ms |
844 KB |
correct |
54 |
Correct |
155 ms |
968 KB |
correct |
55 |
Correct |
137 ms |
908 KB |
correct |
56 |
Correct |
132 ms |
952 KB |
correct |
57 |
Correct |
130 ms |
944 KB |
correct |
58 |
Correct |
1 ms |
204 KB |
correct |
59 |
Correct |
1 ms |
204 KB |
correct |
60 |
Incorrect |
242 ms |
3940 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |