Submission #569694

# Submission time Handle Problem Language Result Execution time Memory
569694 2022-05-27T15:59:46 Z ryangohca Swapping Cities (APIO20_swap) C++17
13 / 100
1090 ms 26708 KB
#include "swap.h"

#include <bits/stdc++.h>
using namespace std;
int p[100001], pweight[100001][20], st[100001], en[100001], lineWeight[100001], twok[100001][20];
void init(int N){
    iota(p, p+N, 0);
    iota(st, st+N, 0);
    iota(en, en+N, 0);
    fill(lineWeight, lineWeight+N, 2e9);
    memset(twok, -1, sizeof twok);
    memset(pweight, -1, sizeof pweight);
}
int fs(int x){
    if (p[x] == x) return x;
    return p[x] = fs(p[x]);
}
void ms(int x, int y, int w){
    int px = fs(x), py = fs(y);
    if (px == py){
        st[px] = en[px] = -1;
        lineWeight[px] = min(lineWeight[px], w);
        return;
    }
    p[py] = px; // px -> py
    //cout << px << ' ' << py << ' ' << w << endl;
    twok[py][0] = px;
    pweight[py][0] = w;
    if (st[px] != -1 && st[py] != -1){
        if ((st[px] == x || en[px] == x) && (st[py] == y || en[py] == y)){
            st[px] = (st[px] == x ? en[px] : st[px]);
            en[px] = (st[py] == y ? en[py] : st[py]);
        } else {
            st[px] = en[px] = -1;
            lineWeight[px] = min(lineWeight[px], w);
        }
    } else {
      	lineWeight[px] = min(lineWeight[px], lineWeight[py]);
    }
}
void init(int N, int M,
          std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    init(N);
    vector<tuple<int, int, int>> edges;
    for (int i = 0; i < M; i++){
        edges.push_back({W[i], U[i], V[i]});
    }
    sort(edges.begin(), edges.end());
    for (auto [w, a, b] : edges){
        ms(a, b, w);
    }
    for (int i = 1; i <= 19; i++){
        for (int j = 0; j < N; j++){
            if (twok[j][i-1] != -1){
                twok[j][i] = twok[twok[j][i-1]][i-1];
                pweight[j][i] = max(pweight[j][i-1], pweight[twok[j][i-1]][i-1]);
            }
        }
    }
}
bool isOkay(int mid, int X, int Y){
    for (int i = 19; i >= 0; i--){
        if (twok[X][i] != -1 && pweight[X][i] <= mid) X = twok[X][i];
        if (twok[Y][i] != -1 && pweight[Y][i] <= mid) Y = twok[Y][i];
    }
    //if (twok[X][0] != -1) X = twok[X][0];
    //if (twok[Y][0] != -1) Y = twok[Y][0];
    if (X != Y) return false;
    return lineWeight[X] != -1 && lineWeight[X] <= mid;
}
int getMinimumFuelCapacity(int X, int Y) {
    int mini = 0, maxi = 1e9+10;
    while (maxi - mini > 1){
        int mid = (maxi + mini) / 2;
        if (isOkay(mid, X, Y)) maxi = mid;
        else mini = mid;
    }
    return (maxi==1e9+10?-1:maxi);
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15956 KB Output is correct
2 Correct 9 ms 15956 KB Output is correct
3 Correct 7 ms 15956 KB Output is correct
4 Correct 9 ms 15956 KB Output is correct
5 Correct 7 ms 15956 KB Output is correct
6 Correct 8 ms 16004 KB Output is correct
7 Correct 7 ms 15956 KB Output is correct
8 Correct 8 ms 15956 KB Output is correct
9 Correct 51 ms 22340 KB Output is correct
10 Correct 68 ms 23428 KB Output is correct
11 Correct 68 ms 23344 KB Output is correct
12 Correct 68 ms 23612 KB Output is correct
13 Correct 87 ms 23600 KB Output is correct
14 Correct 104 ms 22708 KB Output is correct
15 Correct 556 ms 26440 KB Output is correct
16 Correct 587 ms 26328 KB Output is correct
17 Correct 559 ms 26708 KB Output is correct
18 Correct 1090 ms 26632 KB Output is correct
19 Correct 369 ms 22108 KB Output is correct
20 Correct 532 ms 25804 KB Output is correct
21 Correct 553 ms 25776 KB Output is correct
22 Correct 546 ms 26192 KB Output is correct
23 Correct 935 ms 26448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15956 KB Output is correct
2 Correct 9 ms 15956 KB Output is correct
3 Correct 416 ms 22788 KB Output is correct
4 Correct 420 ms 22876 KB Output is correct
5 Correct 433 ms 22960 KB Output is correct
6 Correct 445 ms 22852 KB Output is correct
7 Correct 425 ms 22936 KB Output is correct
8 Correct 442 ms 22780 KB Output is correct
9 Correct 434 ms 22904 KB Output is correct
10 Correct 466 ms 22740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15956 KB Output is correct
2 Correct 9 ms 15956 KB Output is correct
3 Correct 7 ms 15956 KB Output is correct
4 Correct 9 ms 15956 KB Output is correct
5 Correct 7 ms 15956 KB Output is correct
6 Correct 8 ms 16004 KB Output is correct
7 Correct 7 ms 15956 KB Output is correct
8 Correct 8 ms 15956 KB Output is correct
9 Correct 7 ms 15956 KB Output is correct
10 Correct 7 ms 15932 KB Output is correct
11 Correct 9 ms 15936 KB Output is correct
12 Correct 8 ms 15936 KB Output is correct
13 Correct 8 ms 15956 KB Output is correct
14 Correct 9 ms 15968 KB Output is correct
15 Correct 8 ms 16004 KB Output is correct
16 Correct 8 ms 15956 KB Output is correct
17 Incorrect 8 ms 15956 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15956 KB Output is correct
2 Correct 7 ms 15956 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 7 ms 15956 KB Output is correct
5 Correct 9 ms 15956 KB Output is correct
6 Correct 7 ms 15956 KB Output is correct
7 Correct 8 ms 16004 KB Output is correct
8 Correct 7 ms 15956 KB Output is correct
9 Correct 8 ms 15956 KB Output is correct
10 Correct 51 ms 22340 KB Output is correct
11 Correct 68 ms 23428 KB Output is correct
12 Correct 68 ms 23344 KB Output is correct
13 Correct 68 ms 23612 KB Output is correct
14 Correct 87 ms 23600 KB Output is correct
15 Correct 7 ms 15932 KB Output is correct
16 Correct 9 ms 15936 KB Output is correct
17 Correct 8 ms 15936 KB Output is correct
18 Correct 8 ms 15956 KB Output is correct
19 Correct 9 ms 15968 KB Output is correct
20 Correct 8 ms 16004 KB Output is correct
21 Correct 8 ms 15956 KB Output is correct
22 Incorrect 8 ms 15956 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15956 KB Output is correct
2 Correct 9 ms 15956 KB Output is correct
3 Correct 7 ms 15956 KB Output is correct
4 Correct 9 ms 15956 KB Output is correct
5 Correct 7 ms 15956 KB Output is correct
6 Correct 8 ms 16004 KB Output is correct
7 Correct 7 ms 15956 KB Output is correct
8 Correct 8 ms 15956 KB Output is correct
9 Correct 51 ms 22340 KB Output is correct
10 Correct 68 ms 23428 KB Output is correct
11 Correct 68 ms 23344 KB Output is correct
12 Correct 68 ms 23612 KB Output is correct
13 Correct 87 ms 23600 KB Output is correct
14 Correct 104 ms 22708 KB Output is correct
15 Correct 556 ms 26440 KB Output is correct
16 Correct 587 ms 26328 KB Output is correct
17 Correct 559 ms 26708 KB Output is correct
18 Correct 1090 ms 26632 KB Output is correct
19 Correct 416 ms 22788 KB Output is correct
20 Correct 420 ms 22876 KB Output is correct
21 Correct 433 ms 22960 KB Output is correct
22 Correct 445 ms 22852 KB Output is correct
23 Correct 425 ms 22936 KB Output is correct
24 Correct 442 ms 22780 KB Output is correct
25 Correct 434 ms 22904 KB Output is correct
26 Correct 466 ms 22740 KB Output is correct
27 Correct 7 ms 15932 KB Output is correct
28 Correct 9 ms 15936 KB Output is correct
29 Correct 8 ms 15936 KB Output is correct
30 Correct 8 ms 15956 KB Output is correct
31 Correct 9 ms 15968 KB Output is correct
32 Correct 8 ms 16004 KB Output is correct
33 Correct 8 ms 15956 KB Output is correct
34 Incorrect 8 ms 15956 KB Output isn't correct
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15956 KB Output is correct
2 Correct 7 ms 15956 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 7 ms 15956 KB Output is correct
5 Correct 9 ms 15956 KB Output is correct
6 Correct 7 ms 15956 KB Output is correct
7 Correct 8 ms 16004 KB Output is correct
8 Correct 7 ms 15956 KB Output is correct
9 Correct 8 ms 15956 KB Output is correct
10 Correct 51 ms 22340 KB Output is correct
11 Correct 68 ms 23428 KB Output is correct
12 Correct 68 ms 23344 KB Output is correct
13 Correct 68 ms 23612 KB Output is correct
14 Correct 87 ms 23600 KB Output is correct
15 Correct 104 ms 22708 KB Output is correct
16 Correct 556 ms 26440 KB Output is correct
17 Correct 587 ms 26328 KB Output is correct
18 Correct 559 ms 26708 KB Output is correct
19 Correct 1090 ms 26632 KB Output is correct
20 Correct 416 ms 22788 KB Output is correct
21 Correct 420 ms 22876 KB Output is correct
22 Correct 433 ms 22960 KB Output is correct
23 Correct 445 ms 22852 KB Output is correct
24 Correct 425 ms 22936 KB Output is correct
25 Correct 442 ms 22780 KB Output is correct
26 Correct 434 ms 22904 KB Output is correct
27 Correct 466 ms 22740 KB Output is correct
28 Correct 7 ms 15932 KB Output is correct
29 Correct 9 ms 15936 KB Output is correct
30 Correct 8 ms 15936 KB Output is correct
31 Correct 8 ms 15956 KB Output is correct
32 Correct 9 ms 15968 KB Output is correct
33 Correct 8 ms 16004 KB Output is correct
34 Correct 8 ms 15956 KB Output is correct
35 Incorrect 8 ms 15956 KB Output isn't correct
36 Halted 0 ms 0 KB -