Submission #1067442

# Submission time Handle Problem Language Result Execution time Memory
1067442 2024-08-20T17:03:45 Z Ignut Simurgh (IOI17_simurgh) C++17
0 / 100
3000 ms 5980 KB
// Ignut
 
#include "simurgh.h"
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
// int count_common_roads(vector<int> r);
 
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])) {
            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 == 10) return vec;
        shuffle(vec.begin(), vec.end(), rnd);
        vector<int> v;
        DSU dsu; dsu.Init(n);
        // for (int val : vec) cout << val << ' ';
        // cout << '\n';
        for (int i = 0; i < m; i ++) {
            
            // cout << "unite " << i << ' ' << v[i] << '\n'; 
            // continue;
            if (dsu.Unite(u[vec[i]], V[vec[i]])) {
                v.push_back(vec[i]);
            }
        }
        // cout << "-- " << v.size() << '\n';
        int ccr = count_common_roads(v);
        if (ccr == n - 1) return v;
        if (ccr == 0) {
            vec = v;
            break;
        }
    }
 
    // cout << "go\n";
 
    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:72:9: warning: unused variable 'oper' [-Wunused-variable]
   72 |     int 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 Correct 0 ms 348 KB correct
3 Correct 125 ms 4212 KB correct
4 Correct 202 ms 5968 KB correct
5 Correct 205 ms 5980 KB correct
6 Execution timed out 3055 ms 5980 KB Time limit exceeded
7 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 -