이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "simurgh.h"
using namespace std;
vector<int> U, V, ans;
int N, M;
bool flag = false;
void DFS(int u, vector<bool>& vis, vector<vector<int>>& G) {
vis[u] = true;
for(int v : G[u]) {
if(!vis[v]) DFS(v, vis, G);
}
}
void test(int msk) {
bool can = true;
vector<int> r(N-1);
vector<vector<int>> G(N);
vector<int> nodes;
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]);
nodes.push_back(U[j]);
nodes.push_back(V[j]);
}
DFS(nodes[0], vis, G);
for(int it : nodes)
if(!vis[it]) can = false;
if(!can) return;
if(count_common_roads(r) == N-1) {
ans = r;
flag = true;
}
}
void solve(int msk) {
if(flag) return;
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, vector<int> u, vector<int> 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |