Submission #598157

# Submission time Handle Problem Language Result Execution time Memory
598157 2022-07-17T18:18:16 Z yanndev Simurgh (IOI17_simurgh) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#include "simurgh.h"
#define fi first
#define se second
using namespace std;

const int IDK = 0;
const int NOT_ROYAL = 1;
const int ROYAL = 2;

vector<pair<int, int>> graph[542];
bool vis[542];
bool dfsTree[4242];
int status[4242];
int par[542];
vector<int> cur {};

int find(int node) {
    return (par[node] < 0 ? node : par[node] = find(par[node]));
}

int sz(int node) {
    return -par[find(node)];
}

bool unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b)
        return false;
    if (sz(a) < sz(b))
        swap(a, b);
    par[a] += par[b];
    par[b] = a;
    return true;
}

void resetDsu(int n) {
    for (int i = 0; i < n; i++)
        par[i] = -1;
}

void dfs(int node) {
    vis[node] = true;
    for (auto& x: graph[node]) {
        if (!vis[x.fi]) {
            //printf("add edge %d\n", x.se);
            dfsTree[x.se] = true;
            cur.push_back(x.se);
            dfs(x.fi);
        }
    }
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
    int m = (int)u.size();
    for (int i = 0; i < m; i++) {
        graph[u[i]].push_back({v[i], i});
        graph[v[i]].push_back({u[i], i});
    }

    memset(vis, false, sizeof(vis));
    memset(dfsTree, false, sizeof(dfsTree));
    dfs(0);

    for (int i = 0; i < 2; i++) {
        int orig = count_common_roads(cur);
        bool done = false;
        for (int idRem = 0; idRem < (int)cur.size(); idRem++) {
            if (done)
                break;
            vector<int> newTree {};
            for (auto& x: cur)
                if (x != cur[idRem])
                    newTree.push_back(x);
                    
            for (int toAdd = 0; toAdd < m; toAdd++) {
                if (!dfsTree[toAdd]) {
                    newTree.push_back(toAdd);
                    resetDsu(n);
                    bool ok = true;
                    for (auto& x: newTree) {
                        if (!unite(u[x], v[x]))
                            ok = false;
                    }

                    if (sz(0) != n)
                        ok = false;

                    int newCnt = count_common_roads(newTree);
                    if (newCnt > orig) {
                        cur = newTree;
                        done = true;
                        break;
                    }
                    newTree.pop_back();
                }
            }
        }
    }

    /*printf("ans ");
    for (auto& x: ans)
        printf("%d ", x);
    printf("\n");*/
    return cur;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:81:26: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   81 |                     bool ok = true;
      |                          ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Incorrect 0 ms 212 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -