답안 #296023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
296023 2020-09-10T07:50:36 Z Alexa2001 자매 도시 (APIO20_swap) C++17
13 / 100
189 ms 12376 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);
            chain[x] = 0;
            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 2 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 66 ms 8056 KB Output is correct
10 Correct 87 ms 9336 KB Output is correct
11 Correct 91 ms 9212 KB Output is correct
12 Correct 92 ms 9592 KB Output is correct
13 Correct 69 ms 8828 KB Output is correct
14 Correct 75 ms 8312 KB Output is correct
15 Correct 178 ms 11000 KB Output is correct
16 Correct 184 ms 10744 KB Output is correct
17 Correct 189 ms 11104 KB Output is correct
18 Correct 146 ms 10356 KB Output is correct
19 Correct 83 ms 7288 KB Output is correct
20 Correct 179 ms 12152 KB Output is correct
21 Correct 180 ms 12100 KB Output is correct
22 Correct 186 ms 12376 KB Output is correct
23 Correct 149 ms 11732 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 11168 KB Output is correct
4 Correct 140 ms 11216 KB Output is correct
5 Correct 138 ms 11536 KB Output is correct
6 Correct 137 ms 11216 KB Output is correct
7 Correct 141 ms 11376 KB Output is correct
8 Correct 135 ms 11184 KB Output is correct
9 Correct 136 ms 11248 KB Output is correct
10 Correct 136 ms 11200 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 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 2 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 2 ms 2816 KB Output is correct
10 Correct 2 ms 2816 KB Output is correct
11 Correct 3 ms 2816 KB Output is correct
12 Correct 3 ms 2816 KB Output is correct
13 Incorrect 2 ms 2688 KB Output isn't correct
14 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 2 ms 2688 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 2 ms 2816 KB Output is correct
10 Correct 66 ms 8056 KB Output is correct
11 Correct 87 ms 9336 KB Output is correct
12 Correct 91 ms 9212 KB Output is correct
13 Correct 92 ms 9592 KB Output is correct
14 Correct 69 ms 8828 KB Output is correct
15 Correct 2 ms 2816 KB Output is correct
16 Correct 3 ms 2816 KB Output is correct
17 Correct 3 ms 2816 KB Output is correct
18 Incorrect 2 ms 2688 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 2 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 66 ms 8056 KB Output is correct
10 Correct 87 ms 9336 KB Output is correct
11 Correct 91 ms 9212 KB Output is correct
12 Correct 92 ms 9592 KB Output is correct
13 Correct 69 ms 8828 KB Output is correct
14 Correct 75 ms 8312 KB Output is correct
15 Correct 178 ms 11000 KB Output is correct
16 Correct 184 ms 10744 KB Output is correct
17 Correct 189 ms 11104 KB Output is correct
18 Correct 146 ms 10356 KB Output is correct
19 Correct 133 ms 11168 KB Output is correct
20 Correct 140 ms 11216 KB Output is correct
21 Correct 138 ms 11536 KB Output is correct
22 Correct 137 ms 11216 KB Output is correct
23 Correct 141 ms 11376 KB Output is correct
24 Correct 135 ms 11184 KB Output is correct
25 Correct 136 ms 11248 KB Output is correct
26 Correct 136 ms 11200 KB Output is correct
27 Correct 2 ms 2816 KB Output is correct
28 Correct 3 ms 2816 KB Output is correct
29 Correct 3 ms 2816 KB Output is correct
30 Incorrect 2 ms 2688 KB Output isn't correct
31 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 2 ms 2688 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 2 ms 2816 KB Output is correct
10 Correct 66 ms 8056 KB Output is correct
11 Correct 87 ms 9336 KB Output is correct
12 Correct 91 ms 9212 KB Output is correct
13 Correct 92 ms 9592 KB Output is correct
14 Correct 69 ms 8828 KB Output is correct
15 Correct 75 ms 8312 KB Output is correct
16 Correct 178 ms 11000 KB Output is correct
17 Correct 184 ms 10744 KB Output is correct
18 Correct 189 ms 11104 KB Output is correct
19 Correct 146 ms 10356 KB Output is correct
20 Correct 133 ms 11168 KB Output is correct
21 Correct 140 ms 11216 KB Output is correct
22 Correct 138 ms 11536 KB Output is correct
23 Correct 137 ms 11216 KB Output is correct
24 Correct 141 ms 11376 KB Output is correct
25 Correct 135 ms 11184 KB Output is correct
26 Correct 136 ms 11248 KB Output is correct
27 Correct 136 ms 11200 KB Output is correct
28 Correct 2 ms 2816 KB Output is correct
29 Correct 3 ms 2816 KB Output is correct
30 Correct 3 ms 2816 KB Output is correct
31 Incorrect 2 ms 2688 KB Output isn't correct
32 Halted 0 ms 0 KB -