Submission #434322

# Submission time Handle Problem Language Result Execution time Memory
434322 2021-06-20T23:48:26 Z Monchito Simurgh (IOI17_simurgh) C++14
0 / 100
1809 ms 272 KB
#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 u=0; u<N; u++)
        if(!vis[u]) 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
1 Incorrect 118 ms 272 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 118 ms 272 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 118 ms 272 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB correct
2 Incorrect 1809 ms 256 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 118 ms 272 KB WA in grader: NO
2 Halted 0 ms 0 KB -