#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM)
#define ss second
#define ff first
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int,int>>
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vdd vector<pdd>
#define dte tuple<double , double , double>
using namespace std;
const int INF = 1000*1000*1000; // 1 e 9
const int MOD = 1e9 + 7;//998244353 ;
const double EPS = 0.000000001; // 1 e -9
const ll inf = (ll)1e18;
#include"simurgh.h"
/*int count_common_roads(vi v){
cout << "req ";
for(auto c : v) cout << c << " "; cout << endl;
int ans; cin>>ans; return ans;
}*/
int n , m;
vi adj[505];
int nb[505][505];
vi v , ans;
bool vis[7];
bool ok[50];
int cnt = 0;
void dfs(int pos){
if(vis[pos]) return ;
vis[pos] = true; cnt++;
for(auto c : adj[pos]) if(ok[nb[pos][c]]) dfs(c);
}
vi find_roads(int N , vi a , vi b){
n = N; m = a.size();
if(n > 7) return ans;
for(int i = 0 ; i < m ; i++){
int x = a[i] , y = b[i];
nb[x][y] = nb[y][x] = i;
adj[x].pb(y); adj[y].pb(x);
}
for(int i = 0 ; i < (1 << m) ; i++){
v.clear();
for(int j = 0 ; j < m ; j++){
if((1 << j) & i){
v.pb(j); ok[j] = true;
}
else ok[j] = false;
}
if(v.size() != n - 1) continue;
memset(vis , 0 , sizeof vis); cnt = 0;
dfs(0);
if(cnt == n) {
int x = count_common_roads(v);
if(x == n - 1) return v;
}
}
return ans;
}
/*int main(){
//ifstream fin ("testing.txt");
//ofstream fout ("output.txt");
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int nn , mm; cin>>nn>>mm;
vi a(mm) , b(mm); for(int i = 0 ; i < mm ; i++) cin>>a[i]>>b[i];
for(auto c : find_roads(nn , a , b)) cout << c << " "; cout << "\n";
return 0;
}*/
/*
4 6
0 1
0 2
0 3
1 2
1 3
2 3
*/
/*
Think of : BS / DFS / BFS / SSSP / SCC / MSP / MAX FLOW / TOPSORT / LCA / MATRIX / DP(bitmask) / 2 POINTERS / SEG TREE / MATH / UN FIND / MO / HLD
Read the statement CAREFULLY !!
Make a GREADY APPROACH !!!! (start from highest / lowest)
Make your own TESTS !!
Be careful from CORNER CASES !
*/
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:61:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
61 | if(v.size() != n - 1) continue;
| ~~~~~~~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
212 KB |
correct |
2 |
Correct |
135 ms |
308 KB |
correct |
3 |
Correct |
174 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
316 KB |
correct |
6 |
Correct |
5 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
316 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
2 ms |
296 KB |
correct |
11 |
Correct |
1 ms |
212 KB |
correct |
12 |
Correct |
2 ms |
212 KB |
correct |
13 |
Correct |
48 ms |
212 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
212 KB |
correct |
2 |
Correct |
135 ms |
308 KB |
correct |
3 |
Correct |
174 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
316 KB |
correct |
6 |
Correct |
5 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
316 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
2 ms |
296 KB |
correct |
11 |
Correct |
1 ms |
212 KB |
correct |
12 |
Correct |
2 ms |
212 KB |
correct |
13 |
Correct |
48 ms |
212 KB |
correct |
14 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
212 KB |
correct |
2 |
Correct |
135 ms |
308 KB |
correct |
3 |
Correct |
174 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
316 KB |
correct |
6 |
Correct |
5 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
316 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
2 ms |
296 KB |
correct |
11 |
Correct |
1 ms |
212 KB |
correct |
12 |
Correct |
2 ms |
212 KB |
correct |
13 |
Correct |
48 ms |
212 KB |
correct |
14 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Incorrect |
1 ms |
212 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
212 KB |
correct |
2 |
Correct |
135 ms |
308 KB |
correct |
3 |
Correct |
174 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
316 KB |
correct |
6 |
Correct |
5 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
316 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
2 ms |
296 KB |
correct |
11 |
Correct |
1 ms |
212 KB |
correct |
12 |
Correct |
2 ms |
212 KB |
correct |
13 |
Correct |
48 ms |
212 KB |
correct |
14 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |