#include "simurgh.h"
#include <iostream>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
vi U, V;
int N;
void DFS(int u, vector<bool>& vis, vvi& G) {
vis[u] = true;
for(int v : G[u]) {
if(!vis[v]) DFS(v, vis, G);
}
}
bool check(vector<int>& edges) {
vvi G(N);
vector<bool> vis(N, false);
for(int i=0; i<N-1; i++) {
int j = edges[i];
G[U[j]].push_back(V[j]);
G[V[j]].push_back(U[j]);
}
DFS(0, vis, G);
for(int i=0; i<N; i++) if(!vis[i])
return false;
return true;
}
vector<int> find_roads(int n, vi u, vi v) {
N = n;
int m = (int)u.size();
U = u;
V = v;
for(int msk=0; msk < (1<<m); msk++) {
if(__builtin_popcount(msk) == n-1) {
vector<int> edges;
for(int i=0; i<m; i++) {
if(msk & (1<<i)) edges.push_back(i);
}
if(check(edges) && count_common_roads(edges) == n-1) return edges;
}
}
return vector<int>(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
284 KB |
correct |
2 |
Correct |
53 ms |
276 KB |
correct |
3 |
Correct |
64 ms |
288 KB |
correct |
4 |
Correct |
2 ms |
204 KB |
correct |
5 |
Correct |
1 ms |
204 KB |
correct |
6 |
Correct |
6 ms |
204 KB |
correct |
7 |
Correct |
1 ms |
204 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
2 ms |
204 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
3 ms |
292 KB |
correct |
13 |
Correct |
27 ms |
204 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
284 KB |
correct |
2 |
Correct |
53 ms |
276 KB |
correct |
3 |
Correct |
64 ms |
288 KB |
correct |
4 |
Correct |
2 ms |
204 KB |
correct |
5 |
Correct |
1 ms |
204 KB |
correct |
6 |
Correct |
6 ms |
204 KB |
correct |
7 |
Correct |
1 ms |
204 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
2 ms |
204 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
3 ms |
292 KB |
correct |
13 |
Correct |
27 ms |
204 KB |
correct |
14 |
Incorrect |
1 ms |
296 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
284 KB |
correct |
2 |
Correct |
53 ms |
276 KB |
correct |
3 |
Correct |
64 ms |
288 KB |
correct |
4 |
Correct |
2 ms |
204 KB |
correct |
5 |
Correct |
1 ms |
204 KB |
correct |
6 |
Correct |
6 ms |
204 KB |
correct |
7 |
Correct |
1 ms |
204 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
2 ms |
204 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
3 ms |
292 KB |
correct |
13 |
Correct |
27 ms |
204 KB |
correct |
14 |
Incorrect |
1 ms |
296 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Incorrect |
2 ms |
204 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
284 KB |
correct |
2 |
Correct |
53 ms |
276 KB |
correct |
3 |
Correct |
64 ms |
288 KB |
correct |
4 |
Correct |
2 ms |
204 KB |
correct |
5 |
Correct |
1 ms |
204 KB |
correct |
6 |
Correct |
6 ms |
204 KB |
correct |
7 |
Correct |
1 ms |
204 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
2 ms |
204 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
3 ms |
292 KB |
correct |
13 |
Correct |
27 ms |
204 KB |
correct |
14 |
Incorrect |
1 ms |
296 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |