#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int>>>adj(505);
vector<vector<int>>adj1(505);
vector<bool> vis(505,0);
void DFS(int n){
vis[n] = 1;
for(auto x: adj1[n]){
if(vis[x])continue;
DFS(x);
}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
vector<pair<int,int>> edges;
vector<int> r;
int res=0;
for(int i=0; i < u.size(); i++){
edges.push_back({u[i],v[i]});
adj[u[i]].push_back({v[i],i});
adj[v[i]].push_back({u[i],i});
}
for(auto [x,y]: adj[0]){
r.push_back(y);
//cout<<y<<" ";
}
//cout<<endl;
int pos=0, lastres = 0, last = 0;
/*if(edges.size() == (n*(n-1))/2){
vector<bool> used(edges.size(),0);
for(auto x: r){
used[x] = 1;
}
res = count_common_roads(r);
while(pos < n-1 && res < n-1){
for(auto [x,y]: adj[edges[r[pos]].second]){
if(!used[y]){
last = r[pos];
r[pos] = y;
used[y] = 1;
break;
}
}
lastres = res;
res = count_common_roads(r);
/*for(auto x: r){
cout<<x<<" ";
}
cout<<endl;*/
if(lastres < res){
pos++;
}else if(lastres == res){
for(auto [x,y]: adj[edges[r[pos]].first]){
used[y] = 1;
}
for(auto [x,y]: adj[edges[r[pos]].second]){
used[y] = 1;
}
used[r[pos]] = 0;
r[pos] = last;
pos++;
res = lastres;
}else if(lastres > res){
r[pos] = last;
pos++;
res = lastres;
}
}
return r;
}*/
for(int b=0; b < (1<<edges.size()); b++){
r.clear();
for(int i=0; i < n; i++){
adj1[i].clear();
vis[i] = 0;
}
for(int i=0; i < edges.size(); i++){
if(b & (1<<i)){
adj1[edges[i].first].push_back(edges[i].second);
adj1[edges[i].second].push_back(edges[i].first);
r.push_back(i);
}
}
if(r.size() != n-1){
continue;
}
DFS(0);
int cnt = 0;
for(int i=0; i < n; i++){
if(vis[i]){
cnt++;
}else{
break;
}
}
if(cnt == n){
res = count_common_roads(r);
}else{
continue;
}
if(res == n-1){
return r;
}
}
return {0};
}
Compilation message
simurgh.cpp:52:13: warning: "/*" within comment [-Wcomment]
52 | /*for(auto x: r){
|
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=0; i < u.size(); i++){
| ~~^~~~~~~~~~
simurgh.cpp:60:21: error: 'used' was not declared in this scope
60 | used[y] = 1;
| ^~~~
simurgh.cpp:63:21: error: 'used' was not declared in this scope
63 | used[y] = 1;
| ^~~~
simurgh.cpp:65:17: error: 'used' was not declared in this scope
65 | used[r[pos]] = 0;
| ^~~~
simurgh.cpp:74:9: warning: no return statement in function returning non-void [-Wreturn-type]
74 | }
| ^
simurgh.cpp: At global scope:
simurgh.cpp:75:9: error: expected unqualified-id before 'return'
75 | return r;
| ^~~~~~
simurgh.cpp:76:2: error: expected declaration before '}' token
76 | }*/
| ^
simurgh.cpp:76:4: error: expected unqualified-id before '/' token
76 | }*/
| ^
simurgh.cpp:78:15: error: 'b' does not name a type
78 | for(int b=0; b < (1<<edges.size()); b++){
| ^
simurgh.cpp:78:38: error: 'b' does not name a type
78 | for(int b=0; b < (1<<edges.size()); b++){
| ^
simurgh.cpp:117:2: error: expected unqualified-id before 'return'
117 | return {0};
| ^~~~~~
simurgh.cpp:118:1: error: expected declaration before '}' token
118 | }
| ^