답안 #296022

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
296022 2020-09-10T07:48:07 Z Alexa2001 자매 도시 (APIO20_swap) C++17
13 / 100
187 ms 16728 KB
#include "swap.h"
#include <bits/stdc++.h>

using namespace std;

const int inf = 1e9 + 5;
const int Nmax = 1e5 + 5;

int rang[Nmax], t[Nmax], A[Nmax], B[Nmax], up[Nmax], good[Nmax], level[Nmax];
bool chain[Nmax];

int n, m;
vector<int> v[Nmax];


int boss(int x)
{
    if(x == t[x]) return x;
    return t[x] = boss(t[x]);
}

bool endpoints(int x, int y, int a, int b)
{
    //assert(boss(a) == x && boss(b) == y);
    return (A[x] == a || B[x] == a) && (A[y] == b || B[y] == b);
}

void combine_chains(int x, int y, int a, int b)
{
    B[y] = (A[y] == b ? B[y] : A[y]);
    A[y] = (A[x] == a ? B[x] : A[x]);
}

void dfs(int node)
{
    for(auto it : v[node])
    {
        good[it] = min(good[it], max(good[node], up[it]));
        level[it] = level[node] + 1;
        dfs(it);
    }
}

void init(int N, int M,  vector<int> U, vector<int> V, vector<int> W)
{
    n = N; m = M;

    vector<int> ord(m);
    iota(ord.begin(), ord.end(), 0);

    sort(ord.begin(), ord.end(), [&] (int x, int y) { return W[x] < W[y]; } );

    for(int j = 0; j<n; ++j)
    {
        good[j] = inf;
        chain[j] = 1;
        A[j] = B[j] = j;
        rang[j] = 0;
        t[j] = j;
    }

    for(auto i : ord)
    {
        int x = U[i], y = V[i], cost = W[i];

        x = boss(x);
        y = boss(y);

        if(x == y)
        {
            good[x] = min(good[x], cost);
            continue;
        }

        if(rang[x] > rang[y])
        {
            swap(x, y);
            swap(U[i], V[i]);
        }

        if(rang[x] == rang[y]) ++rang[y];

        t[x] = y;
        v[y].push_back(x);
        up[x] = cost;

        if(chain[y])
        {
            if(!chain[x] || (chain[x] && !endpoints(x, y, U[i], V[i])))
                chain[y] = 0, good[y] = min(good[y], cost);
            else if(chain[x])
                combine_chains(x, y, U[i], V[i]);
        }
    }

    dfs(boss(1));
}

int getMinimumFuelCapacity(int x, int y)
{
    int ans = 0;

    while(x != y)
    {
        if(level[x] > level[y]) ans = max(ans, up[x]), x = t[x];
            else ans = max(ans, up[y]), y = t[y];
    }

    ans = max(ans, good[x]);

    if(ans == inf) return -1;
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 3 ms 2816 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 68 ms 9944 KB Output is correct
10 Correct 85 ms 11384 KB Output is correct
11 Correct 85 ms 11256 KB Output is correct
12 Correct 88 ms 11640 KB Output is correct
13 Correct 66 ms 10932 KB Output is correct
14 Correct 75 ms 10104 KB Output is correct
15 Correct 172 ms 15224 KB Output is correct
16 Correct 171 ms 14968 KB Output is correct
17 Correct 187 ms 15480 KB Output is correct
18 Correct 144 ms 14708 KB Output is correct
19 Correct 83 ms 9208 KB Output is correct
20 Correct 177 ms 16196 KB Output is correct
21 Correct 179 ms 16324 KB Output is correct
22 Correct 183 ms 16728 KB Output is correct
23 Correct 148 ms 16084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 133 ms 11152 KB Output is correct
4 Correct 135 ms 11216 KB Output is correct
5 Correct 138 ms 11384 KB Output is correct
6 Correct 136 ms 11216 KB Output is correct
7 Correct 153 ms 11376 KB Output is correct
8 Correct 133 ms 11188 KB Output is correct
9 Correct 134 ms 11248 KB Output is correct
10 Correct 134 ms 11200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Correct 3 ms 2816 KB Output is correct
11 Correct 3 ms 2816 KB Output is correct
12 Correct 2 ms 2816 KB Output is correct
13 Incorrect 2 ms 2816 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Correct 68 ms 9944 KB Output is correct
11 Correct 85 ms 11384 KB Output is correct
12 Correct 85 ms 11256 KB Output is correct
13 Correct 88 ms 11640 KB Output is correct
14 Correct 66 ms 10932 KB Output is correct
15 Correct 3 ms 2816 KB Output is correct
16 Correct 3 ms 2816 KB Output is correct
17 Correct 2 ms 2816 KB Output is correct
18 Incorrect 2 ms 2816 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 3 ms 2816 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 68 ms 9944 KB Output is correct
10 Correct 85 ms 11384 KB Output is correct
11 Correct 85 ms 11256 KB Output is correct
12 Correct 88 ms 11640 KB Output is correct
13 Correct 66 ms 10932 KB Output is correct
14 Correct 75 ms 10104 KB Output is correct
15 Correct 172 ms 15224 KB Output is correct
16 Correct 171 ms 14968 KB Output is correct
17 Correct 187 ms 15480 KB Output is correct
18 Correct 144 ms 14708 KB Output is correct
19 Correct 133 ms 11152 KB Output is correct
20 Correct 135 ms 11216 KB Output is correct
21 Correct 138 ms 11384 KB Output is correct
22 Correct 136 ms 11216 KB Output is correct
23 Correct 153 ms 11376 KB Output is correct
24 Correct 133 ms 11188 KB Output is correct
25 Correct 134 ms 11248 KB Output is correct
26 Correct 134 ms 11200 KB Output is correct
27 Correct 3 ms 2816 KB Output is correct
28 Correct 3 ms 2816 KB Output is correct
29 Correct 2 ms 2816 KB Output is correct
30 Incorrect 2 ms 2816 KB Output isn't correct
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Correct 68 ms 9944 KB Output is correct
11 Correct 85 ms 11384 KB Output is correct
12 Correct 85 ms 11256 KB Output is correct
13 Correct 88 ms 11640 KB Output is correct
14 Correct 66 ms 10932 KB Output is correct
15 Correct 75 ms 10104 KB Output is correct
16 Correct 172 ms 15224 KB Output is correct
17 Correct 171 ms 14968 KB Output is correct
18 Correct 187 ms 15480 KB Output is correct
19 Correct 144 ms 14708 KB Output is correct
20 Correct 133 ms 11152 KB Output is correct
21 Correct 135 ms 11216 KB Output is correct
22 Correct 138 ms 11384 KB Output is correct
23 Correct 136 ms 11216 KB Output is correct
24 Correct 153 ms 11376 KB Output is correct
25 Correct 133 ms 11188 KB Output is correct
26 Correct 134 ms 11248 KB Output is correct
27 Correct 134 ms 11200 KB Output is correct
28 Correct 3 ms 2816 KB Output is correct
29 Correct 3 ms 2816 KB Output is correct
30 Correct 2 ms 2816 KB Output is correct
31 Incorrect 2 ms 2816 KB Output isn't correct
32 Halted 0 ms 0 KB -