답안 #296024

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
296024 2020-09-10T07:53:32 Z Alexa2001 자매 도시 (APIO20_swap) C++17
13 / 100
198 ms 12372 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);
    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 if(chain[x])
                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 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 2848 KB Output is correct
9 Correct 70 ms 8088 KB Output is correct
10 Correct 90 ms 9336 KB Output is correct
11 Correct 87 ms 9208 KB Output is correct
12 Correct 95 ms 9596 KB Output is correct
13 Correct 71 ms 8756 KB Output is correct
14 Correct 79 ms 8184 KB Output is correct
15 Correct 198 ms 11032 KB Output is correct
16 Correct 186 ms 10744 KB Output is correct
17 Correct 187 ms 11112 KB Output is correct
18 Correct 152 ms 10356 KB Output is correct
19 Correct 86 ms 7288 KB Output is correct
20 Correct 184 ms 12024 KB Output is correct
21 Correct 187 ms 12104 KB Output is correct
22 Correct 196 ms 12372 KB Output is correct
23 Correct 157 ms 11592 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 137 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 137 ms 11216 KB Output is correct
7 Correct 144 ms 11504 KB Output is correct
8 Correct 144 ms 11188 KB Output is correct
9 Correct 140 ms 11248 KB Output is correct
10 Correct 140 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 3 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 3 ms 2848 KB Output is correct
10 Correct 3 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 3 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 3 ms 2848 KB Output is correct
10 Correct 70 ms 8088 KB Output is correct
11 Correct 90 ms 9336 KB Output is correct
12 Correct 87 ms 9208 KB Output is correct
13 Correct 95 ms 9596 KB Output is correct
14 Correct 71 ms 8756 KB Output is correct
15 Correct 3 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 3 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 3 ms 2848 KB Output is correct
9 Correct 70 ms 8088 KB Output is correct
10 Correct 90 ms 9336 KB Output is correct
11 Correct 87 ms 9208 KB Output is correct
12 Correct 95 ms 9596 KB Output is correct
13 Correct 71 ms 8756 KB Output is correct
14 Correct 79 ms 8184 KB Output is correct
15 Correct 198 ms 11032 KB Output is correct
16 Correct 186 ms 10744 KB Output is correct
17 Correct 187 ms 11112 KB Output is correct
18 Correct 152 ms 10356 KB Output is correct
19 Correct 137 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 137 ms 11216 KB Output is correct
23 Correct 144 ms 11504 KB Output is correct
24 Correct 144 ms 11188 KB Output is correct
25 Correct 140 ms 11248 KB Output is correct
26 Correct 140 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 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 3 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 3 ms 2848 KB Output is correct
10 Correct 70 ms 8088 KB Output is correct
11 Correct 90 ms 9336 KB Output is correct
12 Correct 87 ms 9208 KB Output is correct
13 Correct 95 ms 9596 KB Output is correct
14 Correct 71 ms 8756 KB Output is correct
15 Correct 79 ms 8184 KB Output is correct
16 Correct 198 ms 11032 KB Output is correct
17 Correct 186 ms 10744 KB Output is correct
18 Correct 187 ms 11112 KB Output is correct
19 Correct 152 ms 10356 KB Output is correct
20 Correct 137 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 137 ms 11216 KB Output is correct
24 Correct 144 ms 11504 KB Output is correct
25 Correct 144 ms 11188 KB Output is correct
26 Correct 140 ms 11248 KB Output is correct
27 Correct 140 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 3 ms 2816 KB Output is correct
31 Incorrect 2 ms 2688 KB Output isn't correct
32 Halted 0 ms 0 KB -