답안 #296033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
296033 2020-09-10T08:09:57 Z Alexa2001 자매 도시 (APIO20_swap) C++17
100 / 100
279 ms 20172 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 boss(t[x]);
}

bool endpoints(int x, int y, int a, int b)
{
    //assert(boss(a) == x && boss(b) == y);
    assert(chain[x] && chain[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
                combine_chains(x, y, U[i], V[i]);
        }
    }

    dfs(boss(0));
}

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 2 ms 2816 KB Output is correct
6 Correct 2 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 67 ms 8128 KB Output is correct
10 Correct 86 ms 9336 KB Output is correct
11 Correct 84 ms 9336 KB Output is correct
12 Correct 91 ms 9592 KB Output is correct
13 Correct 70 ms 8756 KB Output is correct
14 Correct 75 ms 8264 KB Output is correct
15 Correct 184 ms 10876 KB Output is correct
16 Correct 177 ms 10744 KB Output is correct
17 Correct 191 ms 11072 KB Output is correct
18 Correct 150 ms 10332 KB Output is correct
19 Correct 84 ms 7244 KB Output is correct
20 Correct 185 ms 12020 KB Output is correct
21 Correct 178 ms 11972 KB Output is correct
22 Correct 199 ms 12416 KB Output is correct
23 Correct 153 ms 11584 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 140 ms 11168 KB Output is correct
4 Correct 139 ms 11216 KB Output is correct
5 Correct 144 ms 11408 KB Output is correct
6 Correct 136 ms 11216 KB Output is correct
7 Correct 142 ms 11376 KB Output is correct
8 Correct 137 ms 11184 KB Output is correct
9 Correct 139 ms 11248 KB Output is correct
10 Correct 149 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 2 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 3 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 2 ms 2816 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 3 ms 2816 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 Correct 3 ms 2816 KB Output is correct
19 Correct 3 ms 2816 KB Output is correct
20 Correct 3 ms 2816 KB Output is correct
21 Correct 3 ms 2816 KB Output is correct
22 Correct 3 ms 2816 KB Output is correct
23 Correct 3 ms 2816 KB Output is correct
24 Correct 3 ms 2816 KB Output is correct
25 Correct 3 ms 2816 KB Output is correct
26 Correct 3 ms 2816 KB Output is correct
27 Correct 2 ms 2816 KB Output is correct
28 Correct 3 ms 2816 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 2 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Correct 67 ms 8128 KB Output is correct
11 Correct 86 ms 9336 KB Output is correct
12 Correct 84 ms 9336 KB Output is correct
13 Correct 91 ms 9592 KB Output is correct
14 Correct 70 ms 8756 KB Output is correct
15 Correct 2 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 Correct 3 ms 2688 KB Output is correct
19 Correct 3 ms 2816 KB Output is correct
20 Correct 3 ms 2816 KB Output is correct
21 Correct 3 ms 2816 KB Output is correct
22 Correct 2 ms 2816 KB Output is correct
23 Correct 3 ms 2816 KB Output is correct
24 Correct 12 ms 3840 KB Output is correct
25 Correct 96 ms 11440 KB Output is correct
26 Correct 92 ms 11384 KB Output is correct
27 Correct 91 ms 11384 KB Output is correct
28 Correct 92 ms 11256 KB Output is correct
29 Correct 88 ms 11256 KB Output is correct
30 Correct 76 ms 10476 KB Output is correct
31 Correct 108 ms 11700 KB Output is correct
32 Correct 89 ms 11384 KB Output is correct
33 Correct 68 ms 10608 KB Output is correct
34 Correct 120 ms 11576 KB Output is correct
35 Correct 3 ms 2816 KB Output is correct
36 Correct 3 ms 2816 KB Output is correct
37 Correct 3 ms 2816 KB Output is correct
38 Correct 3 ms 2816 KB Output is correct
39 Correct 3 ms 2816 KB Output is correct
40 Correct 3 ms 2816 KB Output is correct
41 Correct 3 ms 2816 KB Output is correct
42 Correct 3 ms 2816 KB Output is correct
43 Correct 2 ms 2816 KB Output is correct
44 Correct 3 ms 2816 KB Output is correct
45 Correct 116 ms 12920 KB Output is correct
46 Correct 89 ms 11396 KB Output is correct
47 Correct 92 ms 11312 KB Output is correct
48 Correct 89 ms 11768 KB Output is correct
49 Correct 93 ms 9908 KB Output is correct
50 Correct 77 ms 8568 KB Output is correct
51 Correct 117 ms 11640 KB Output is correct
52 Correct 137 ms 14584 KB Output is correct
53 Correct 157 ms 15608 KB Output is correct
54 Correct 165 ms 16248 KB Output is correct
55 Correct 66 ms 10608 KB Output is correct
56 Correct 147 ms 14968 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 2816 KB Output is correct
6 Correct 2 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 67 ms 8128 KB Output is correct
10 Correct 86 ms 9336 KB Output is correct
11 Correct 84 ms 9336 KB Output is correct
12 Correct 91 ms 9592 KB Output is correct
13 Correct 70 ms 8756 KB Output is correct
14 Correct 75 ms 8264 KB Output is correct
15 Correct 184 ms 10876 KB Output is correct
16 Correct 177 ms 10744 KB Output is correct
17 Correct 191 ms 11072 KB Output is correct
18 Correct 150 ms 10332 KB Output is correct
19 Correct 140 ms 11168 KB Output is correct
20 Correct 139 ms 11216 KB Output is correct
21 Correct 144 ms 11408 KB Output is correct
22 Correct 136 ms 11216 KB Output is correct
23 Correct 142 ms 11376 KB Output is correct
24 Correct 137 ms 11184 KB Output is correct
25 Correct 139 ms 11248 KB Output is correct
26 Correct 149 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 2 ms 2816 KB Output is correct
30 Correct 3 ms 2688 KB Output is correct
31 Correct 3 ms 2816 KB Output is correct
32 Correct 3 ms 2816 KB Output is correct
33 Correct 3 ms 2816 KB Output is correct
34 Correct 2 ms 2816 KB Output is correct
35 Correct 3 ms 2816 KB Output is correct
36 Correct 12 ms 3840 KB Output is correct
37 Correct 96 ms 11440 KB Output is correct
38 Correct 92 ms 11384 KB Output is correct
39 Correct 91 ms 11384 KB Output is correct
40 Correct 92 ms 11256 KB Output is correct
41 Correct 88 ms 11256 KB Output is correct
42 Correct 76 ms 10476 KB Output is correct
43 Correct 108 ms 11700 KB Output is correct
44 Correct 89 ms 11384 KB Output is correct
45 Correct 68 ms 10608 KB Output is correct
46 Correct 120 ms 11576 KB Output is correct
47 Correct 20 ms 4352 KB Output is correct
48 Correct 184 ms 15828 KB Output is correct
49 Correct 189 ms 15828 KB Output is correct
50 Correct 192 ms 15960 KB Output is correct
51 Correct 183 ms 15844 KB Output is correct
52 Correct 177 ms 15540 KB Output is correct
53 Correct 151 ms 14180 KB Output is correct
54 Correct 188 ms 16724 KB Output is correct
55 Correct 191 ms 15828 KB Output is correct
56 Correct 150 ms 15188 KB Output is correct
57 Correct 194 ms 16596 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 2 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Correct 67 ms 8128 KB Output is correct
11 Correct 86 ms 9336 KB Output is correct
12 Correct 84 ms 9336 KB Output is correct
13 Correct 91 ms 9592 KB Output is correct
14 Correct 70 ms 8756 KB Output is correct
15 Correct 75 ms 8264 KB Output is correct
16 Correct 184 ms 10876 KB Output is correct
17 Correct 177 ms 10744 KB Output is correct
18 Correct 191 ms 11072 KB Output is correct
19 Correct 150 ms 10332 KB Output is correct
20 Correct 140 ms 11168 KB Output is correct
21 Correct 139 ms 11216 KB Output is correct
22 Correct 144 ms 11408 KB Output is correct
23 Correct 136 ms 11216 KB Output is correct
24 Correct 142 ms 11376 KB Output is correct
25 Correct 137 ms 11184 KB Output is correct
26 Correct 139 ms 11248 KB Output is correct
27 Correct 149 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 2 ms 2816 KB Output is correct
31 Correct 3 ms 2688 KB Output is correct
32 Correct 3 ms 2816 KB Output is correct
33 Correct 3 ms 2816 KB Output is correct
34 Correct 3 ms 2816 KB Output is correct
35 Correct 2 ms 2816 KB Output is correct
36 Correct 3 ms 2816 KB Output is correct
37 Correct 12 ms 3840 KB Output is correct
38 Correct 96 ms 11440 KB Output is correct
39 Correct 92 ms 11384 KB Output is correct
40 Correct 91 ms 11384 KB Output is correct
41 Correct 92 ms 11256 KB Output is correct
42 Correct 88 ms 11256 KB Output is correct
43 Correct 76 ms 10476 KB Output is correct
44 Correct 108 ms 11700 KB Output is correct
45 Correct 89 ms 11384 KB Output is correct
46 Correct 68 ms 10608 KB Output is correct
47 Correct 120 ms 11576 KB Output is correct
48 Correct 20 ms 4352 KB Output is correct
49 Correct 184 ms 15828 KB Output is correct
50 Correct 189 ms 15828 KB Output is correct
51 Correct 192 ms 15960 KB Output is correct
52 Correct 183 ms 15844 KB Output is correct
53 Correct 177 ms 15540 KB Output is correct
54 Correct 151 ms 14180 KB Output is correct
55 Correct 188 ms 16724 KB Output is correct
56 Correct 191 ms 15828 KB Output is correct
57 Correct 150 ms 15188 KB Output is correct
58 Correct 194 ms 16596 KB Output is correct
59 Correct 84 ms 7244 KB Output is correct
60 Correct 185 ms 12020 KB Output is correct
61 Correct 178 ms 11972 KB Output is correct
62 Correct 199 ms 12416 KB Output is correct
63 Correct 153 ms 11584 KB Output is correct
64 Correct 3 ms 2816 KB Output is correct
65 Correct 3 ms 2816 KB Output is correct
66 Correct 3 ms 2816 KB Output is correct
67 Correct 3 ms 2816 KB Output is correct
68 Correct 3 ms 2816 KB Output is correct
69 Correct 3 ms 2816 KB Output is correct
70 Correct 3 ms 2816 KB Output is correct
71 Correct 3 ms 2816 KB Output is correct
72 Correct 2 ms 2816 KB Output is correct
73 Correct 3 ms 2816 KB Output is correct
74 Correct 116 ms 12920 KB Output is correct
75 Correct 89 ms 11396 KB Output is correct
76 Correct 92 ms 11312 KB Output is correct
77 Correct 89 ms 11768 KB Output is correct
78 Correct 93 ms 9908 KB Output is correct
79 Correct 77 ms 8568 KB Output is correct
80 Correct 117 ms 11640 KB Output is correct
81 Correct 137 ms 14584 KB Output is correct
82 Correct 157 ms 15608 KB Output is correct
83 Correct 165 ms 16248 KB Output is correct
84 Correct 66 ms 10608 KB Output is correct
85 Correct 147 ms 14968 KB Output is correct
86 Correct 71 ms 7288 KB Output is correct
87 Correct 197 ms 16000 KB Output is correct
88 Correct 230 ms 15920 KB Output is correct
89 Correct 176 ms 15608 KB Output is correct
90 Correct 236 ms 13688 KB Output is correct
91 Correct 196 ms 13900 KB Output is correct
92 Correct 187 ms 15864 KB Output is correct
93 Correct 270 ms 18772 KB Output is correct
94 Correct 252 ms 19332 KB Output is correct
95 Correct 279 ms 20172 KB Output is correct
96 Correct 155 ms 15360 KB Output is correct
97 Correct 220 ms 17720 KB Output is correct