제출 #1170863

#제출 시각아이디문제언어결과실행 시간메모리
1170863aentrenusMeetings (JOI19_meetings)C++20
0 / 100
2076 ms1588 KiB
#include "meetings.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
#define all(a) a.begin(), a.end()
#define print(a) for (auto elem:a) cout<<elem<<' '; cout<<'\n'
#define segprep(b) resize(1<<((int)ceil(log2(b.size()))+1))
#define FOR(a) for (int _ = 0; _ < a; _++)

const int SEED = 1;

int randint(const int l, const int r){
    int res = rand()%(r-l)+l;
    assert(l <= res && res < r);
    return res;
}

int n;
vector<vi> graph;

void solve_set(vi verts){
    // print(verts);
    if (verts.size() == 1) return;
    if (verts.size() == 2){
        int first = verts.front(), second = verts.back();
        if (first > second) swap(first, second);
        Bridge(first, second);
        graph.at(first).push_back(second);
        graph.at(second).push_back(first);
        return;
    }

    int root_ind = randint(0, (int)verts.size());
    int second_ind = randint(0, (int)verts.size()-1);
    if (second_ind >= root_ind) second_ind++;
    int root = verts.at(root_ind), second = verts.at(second_ind);
    vi subtr = {second};
    vi left_nodes = {root};
    vb in_path_to_second(n, false);
    queue<int> to_chk;
    for (auto &i:verts){
        if (i != root && i != second){
            int ans = Query(root, second, i);
            if (ans == root){
                left_nodes.push_back(i);
                continue;
            }
            subtr.push_back(i);
            if (ans == i){
                in_path_to_second.at(i) = true;;
            }
        }
    }

    solve_set(subtr);
    solve_set(left_nodes);

    // znalezc polaczenie

    int vert = second, parent = second;
    bool moved;
    do{
        moved = false;
        for (const auto &son:graph.at(vert)){
            if (son != parent && in_path_to_second.at(son)){
                parent = vert;
                vert = son;
                moved = true;
            }
        }
    } while(moved);
    if (vert > root) swap(vert, root);
    Bridge(vert, root);
    graph.at(vert).push_back(root);
    graph.at(root).push_back(vert);
}

void Solve(int N){
    n = N;
    srand(SEED);
    graph.resize(n);

    vi nodes(n);
    for (int i = 0; i < n; i++) nodes.at(i) = i;

    solve_set(nodes);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...