#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#define endl '\n'
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
const int N = 3e5+1;
const ll INF = 2e18;
const int MOD = 1e9+7;
vector<vector<pi> > a(N);
bool vs[N],idx[N];
int cnt;
void dfs(int s){
cnt++;
vs[s] = true;
for(auto x : a[s])
if(!vs[x.F] && idx[x.S])
dfs(x.F);
}
int mm,nn;
vector<int> ans;
void solve(int curr, int last){
if(curr == nn-1){
cnt = 0;
dfs(0);
for(int i=0;i<nn;i++)
vs[i] = false;
vector<int> arr;
for(int i=0;i<mm;i++)
if(idx[i]){
arr.push_back(i);
//cout<<i<<" ";
}//cout<<endl;
//cout<<cnt<<endl;
if(cnt != nn)return;
if(count_common_roads(arr) == nn-1){
ans = arr;
return;
}
}
for(int i=last+1;i<mm;i++){
if(idx[i])continue;
idx[i] = true;
solve(curr+1,i);
idx[i] = false;
}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
int i,j;
mm = u.size();
nn = n;
for(i=0;i<mm;i++){
int x = u[i];
int y = v[i];
a[x].push_back({y,i});
a[y].push_back({x,i});
}
solve(0,-1);
return ans;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:60:11: warning: unused variable 'j' [-Wunused-variable]
60 | int i,j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
7244 KB |
correct |
2 |
Correct |
34 ms |
7244 KB |
correct |
3 |
Correct |
34 ms |
7244 KB |
correct |
4 |
Correct |
6 ms |
7244 KB |
correct |
5 |
Correct |
5 ms |
7244 KB |
correct |
6 |
Correct |
10 ms |
7372 KB |
correct |
7 |
Correct |
6 ms |
7244 KB |
correct |
8 |
Correct |
5 ms |
7244 KB |
correct |
9 |
Correct |
5 ms |
7244 KB |
correct |
10 |
Correct |
7 ms |
7368 KB |
correct |
11 |
Correct |
5 ms |
7360 KB |
correct |
12 |
Correct |
7 ms |
7244 KB |
correct |
13 |
Correct |
37 ms |
7244 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
7244 KB |
correct |
2 |
Correct |
34 ms |
7244 KB |
correct |
3 |
Correct |
34 ms |
7244 KB |
correct |
4 |
Correct |
6 ms |
7244 KB |
correct |
5 |
Correct |
5 ms |
7244 KB |
correct |
6 |
Correct |
10 ms |
7372 KB |
correct |
7 |
Correct |
6 ms |
7244 KB |
correct |
8 |
Correct |
5 ms |
7244 KB |
correct |
9 |
Correct |
5 ms |
7244 KB |
correct |
10 |
Correct |
7 ms |
7368 KB |
correct |
11 |
Correct |
5 ms |
7360 KB |
correct |
12 |
Correct |
7 ms |
7244 KB |
correct |
13 |
Correct |
37 ms |
7244 KB |
correct |
14 |
Execution timed out |
3043 ms |
7364 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
7244 KB |
correct |
2 |
Correct |
34 ms |
7244 KB |
correct |
3 |
Correct |
34 ms |
7244 KB |
correct |
4 |
Correct |
6 ms |
7244 KB |
correct |
5 |
Correct |
5 ms |
7244 KB |
correct |
6 |
Correct |
10 ms |
7372 KB |
correct |
7 |
Correct |
6 ms |
7244 KB |
correct |
8 |
Correct |
5 ms |
7244 KB |
correct |
9 |
Correct |
5 ms |
7244 KB |
correct |
10 |
Correct |
7 ms |
7368 KB |
correct |
11 |
Correct |
5 ms |
7360 KB |
correct |
12 |
Correct |
7 ms |
7244 KB |
correct |
13 |
Correct |
37 ms |
7244 KB |
correct |
14 |
Execution timed out |
3043 ms |
7364 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7244 KB |
correct |
2 |
Execution timed out |
3053 ms |
7244 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
7244 KB |
correct |
2 |
Correct |
34 ms |
7244 KB |
correct |
3 |
Correct |
34 ms |
7244 KB |
correct |
4 |
Correct |
6 ms |
7244 KB |
correct |
5 |
Correct |
5 ms |
7244 KB |
correct |
6 |
Correct |
10 ms |
7372 KB |
correct |
7 |
Correct |
6 ms |
7244 KB |
correct |
8 |
Correct |
5 ms |
7244 KB |
correct |
9 |
Correct |
5 ms |
7244 KB |
correct |
10 |
Correct |
7 ms |
7368 KB |
correct |
11 |
Correct |
5 ms |
7360 KB |
correct |
12 |
Correct |
7 ms |
7244 KB |
correct |
13 |
Correct |
37 ms |
7244 KB |
correct |
14 |
Execution timed out |
3043 ms |
7364 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |