#include "simurgh.h"
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
vi U, V, ans;
int N, M;
void DFS(int u, vector<bool>& vis, vvi& G) {
vis[u] = true;
for(int v : G[u]) {
if(!vis[v]) DFS(v, vis, G);
}
}
void test(int msk) {
vi r(N-1);
vvi G(N);
vector<bool> vis(N, false);
for(int i=0, j=0; j < N-1; i++) {
if((msk & (1<<i)) != 0) {
r[j] = i;
j++;
}
}
for(int i=0; i<N-1; i++) {
int j = r[i];
G[U[j]].push_back(V[j]);
G[V[j]].push_back(U[j]);
}
DFS(0, vis, G);
for(int u=0; u<N; u++) if(!vis[u])
return;
if(count_common_roads(r) == N-1) ans = r;
}
void solve(int msk) {
if(__builtin_popcount(msk) == N-1) {
test(msk);
return;
}
for(int i=0; i<M; i++) {
if((msk & (1<<i)) != 0) continue;
int nmsk = (msk | (1<<i));
solve(nmsk);
}
}
vector<int> find_roads(int n, vi u, vi v) {
N = n;
M = (int)u.size();
U = u;
V = v;
ans = vector<int>(n-1);
solve(0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
204 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
204 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
204 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
correct |
2 |
Incorrect |
1367 ms |
276 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
204 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |