답안 #674628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674628 2022-12-25T13:37:23 Z Vahe 자매 도시 (APIO20_swap) C++17
7 / 100
195 ms 14972 KB
#include "swap.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
vector<vector<pair<int, int>>> gp;
int n, m;
vector<int> u_, v_, w, ver, var, par, P, p, her, sizes;
vector<bool> vis;

int get(int u)
{
    if (u == par[u]) return u;
    return par[u] = get(par[u]);
}

void union_chains(int u, int v, int w)
{
    
    int a = get(u), b = get(v);
    if (a == b)
    {
        P[a] = min(P[a], w);
        return;
    }
    gp[u].push_back({ v, w });
    gp[v].push_back({ u, w });
    if (sizes[a] < sizes[b]) swap(a, b);
    sizes[a] += sizes[b];
    par[b] = par[a];
    if      (u == ver[a] && v == ver[b]) ver[a] = var[b];
    else if (u == ver[a] && v == var[b]) ver[a] = ver[b];
    else if (u == var[a] && v == ver[b]) var[a] = var[b];
    else if (u == var[a] && v == var[b]) var[a] = ver[b];
    else ver[a] = -1, var[a] = -1, P[a] = min(P[a], w);
}

void dfs(int u, int o)
{
    vis[u] = 1;
    for (pair<int, int>& p_ : gp[u])
    {
        if (p_.first == o) continue;
        p[p_.first] = u;
        her[p_.first] = p_.second;
        dfs(p_.first, u);
    }
}

int go(int u, int w)
{
    if (p[u] == u || her[u] > w) return u;
    return go(p[u], w);
}

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    n = N, m = M;
    vector<pair<int, pair<int, int>>> kox;
    for (int i = 0; i < m; i++) kox.push_back({ W[i], {U[i], V[i]} });
    sort(kox.begin(), kox.end());
    ver = var = par = sizes = P = her = p = vector<int>(n);
    gp = vector<vector<pair<int, int>>>(n);
    for (int i = 0; i < n; i++) ver[i] = var[i] = par[i] = p[i] = i, sizes[i] = 1, her[i] = P[i] = INT_MAX;
    for (int i = 0; i < m; i++)
    {
        int u = kox[i].second.first, v = kox[i].second.second;
        union_chains(u, v, kox[i].first);
    }
    vis = vector<bool>(n);
    for (int i = 0; i < n; i++)
    {
        if (vis[i]) continue;
        int u = get(i);
        dfs(u, -1);
    }
}

int getMinimumFuelCapacity(int X, int Y) {
    long long l = 0, r = 2e9;
    while (l + 1 < r)
    {
        int mij = l + (r - l) / 2;
        int a = go(X, mij), b = go(Y, mij);
        if (a == b && P[get(a)] <= mij) r = mij;
        else l = mij;
    }
    return r == 2e9 ? -1 : r;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 188 ms 14540 KB Output is correct
4 Correct 190 ms 14904 KB Output is correct
5 Correct 195 ms 14908 KB Output is correct
6 Correct 173 ms 14900 KB Output is correct
7 Correct 192 ms 14960 KB Output is correct
8 Correct 152 ms 14532 KB Output is correct
9 Correct 166 ms 14972 KB Output is correct
10 Correct 167 ms 14564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -