Submission #1067436

# Submission time Handle Problem Language Result Execution time Memory
1067436 2024-08-20T16:59:43 Z Ignut Simurgh (IOI17_simurgh) C++17
0 / 100
17 ms 348 KB
// Ignut

#include "simurgh.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct DSU {
    vector<int> p, sz;
    void Init(int n) {
        p.assign(n, 0);
        iota(p.begin(), p.end(), 0);
        sz.assign(n, 1);
    }
    int Get(int v) {
        return p[v] == v ? v : p[v] = Get(p[v]);
    }
    bool Unite(int u, int v) {
        u = Get(u), v = Get(v);
        if (u == v) return false;
        if (sz[u] > sz[v]) swap(u, v);
        sz[v] += sz[u];
        p[u] = v;
        return true;
    }
};

mt19937 rnd(11223344);

const int N = 555;

vector<int> g[N];
vector<int> U, V;

bool ans[N * N];

vector<int> vec;

vector<int> MakeVector(vector<int> &v, int l, int r) {
    vector<int> res;
    DSU dsu; dsu.Init(N);
    for (int i = l; i <= r; i ++) {
        res.push_back(v[i]);
        dsu.Unite(U[v[i]], V[v[i]]);
    }
    for (int ind : vec) {
        if (dsu.Unite(U[ind], V[ind])) {
            cout << "add\n";
            res.push_back(ind);
        }
    }
    return res;
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
    U = u, V = v;
    int m = u.size();
    for (int i = 0; i < m; i ++) {
        g[u[i]].push_back(i);
        g[v[i]].push_back(i);
    }
    if (n == 2) return {0};
    // for (int val : u) cout << val << '_';
    // cout << '\n';
    // for (int val : v) cout << val << '_';
    // cout << '\n';

    vec.assign(m, 0);
    iota(vec.begin(), vec.end(), 0);
    int oper = 0;
    while (true) {
        oper ++;
        if (oper == 1000) oper /= 0;
        shuffle(vec.begin(), vec.end(), rnd);
        vector<int> v;
        DSU dsu; dsu.Init(n);
        for (int i = 0; i < m; i ++) {
            if (dsu.Unite(u[vec[i]], V[vec[i]])) {
                v.push_back(vec[i]);
            }
        }
        int ccr = count_common_roads(v);
        if (ccr == n - 1) return v;
        if (ccr == 0) {
            vec = v;
            break;
        }
    }

    for (int v = 0; v < n; v ++) {
        int sz = g[v].size();
        int total = count_common_roads(MakeVector(g[v], 0, sz - 1));
        int L = -1;
        for (int j = 0; j < total; j ++) {
            int lo = L + 1, hi = sz - 1;
            while (lo < hi) {
                int mid = lo + (hi - lo) / 2;
                int ccr = count_common_roads(MakeVector(g[v], L + 1, mid));
                if (ccr >= 1)
                    hi = mid;
                else
                    lo = mid + 1;
            }
            ans[g[v][lo]] = true;
            L = lo;
        }
    }

    vector<int> res;
    for (int i = 0; i < m; i ++) if (ans[i]) res.push_back(i);
    return res;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:74:32: warning: division by zero [-Wdiv-by-zero]
   74 |         if (oper == 1000) oper /= 0;
      |                           ~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Incorrect 1 ms 344 KB Security Violation! Don't try to hack
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -