Submission #434311

# Submission time Handle Problem Language Result Execution time Memory
434311 2021-06-20T23:01:45 Z Monchito Simurgh (IOI17_simurgh) C++14
0 / 100
1 ms 204 KB
#include "simurgh.h"
#include <unordered_set>
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);
    unordered_set<int> s;
    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]);
        s.insert(U[j]);
        s.insert(V[j]);
    }

    DFS(*s.begin(), vis, G);

    for(auto it : s)
        if(!vis[it]) can = false;

    if(!can) return;
    if(count_common_roads(r) == N-1) {
        ans = r;
        flag = true;
        return;
    }
}

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
1 Incorrect 1 ms 204 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 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 1 ms 204 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB WA in grader: NO
2 Halted 0 ms 0 KB -