#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];
bool vis[505][(1 << 7)];
int nb[505][505];
vi v , ans;
int q = 0;
void dfs(int pos , int mask){
//cout << pos << " " << mask << "\n";
if(pos == n){
if(mask != (1 << n) - 1 || v.size() < n - 1) return ;
int x = count_common_roads(v);
if(x == n - 1) ans = v;
return ;
}
int x = adj[pos].size();
for(int i = 0 ; i < (1 << x) ; i++){
int cur = i ? (1 << pos) : 0 ; bool ok = true;
vi a;
for(int j = 0 ; j < x ; j++){
if((1 << j) & i){
if(mask & (1 << adj[pos][j])){
ok = false; break;
}
cur += (1 << adj[pos][j]);
a.pb(nb[pos][adj[pos][j]]);
}
}
if(!ok) continue;
for(auto c : a) v.pb(c);
dfs(pos + 1 , mask | cur);
for(int k = 0 ; k < a.size() ; k++) v.pop_back();
}
}
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);
}
dfs(0 , 0);
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 'void dfs(int, int)':
simurgh.cpp:42:45: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
42 | if(mask != (1 << n) - 1 || v.size() < n - 1) return ;
| ~~~~~~~~~^~~~~~~~
simurgh.cpp:63:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int k = 0 ; k < a.size() ; k++) v.pop_back();
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
212 KB |
correct |
2 |
Correct |
25 ms |
212 KB |
correct |
3 |
Incorrect |
26 ms |
212 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
212 KB |
correct |
2 |
Correct |
25 ms |
212 KB |
correct |
3 |
Incorrect |
26 ms |
212 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
212 KB |
correct |
2 |
Correct |
25 ms |
212 KB |
correct |
3 |
Incorrect |
26 ms |
212 KB |
WA in grader: NO |
4 |
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 |
24 ms |
212 KB |
correct |
2 |
Correct |
25 ms |
212 KB |
correct |
3 |
Incorrect |
26 ms |
212 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |