Submission #394221

# Submission time Handle Problem Language Result Execution time Memory
394221 2021-04-26T07:17:39 Z two_sides Swapping Cities (APIO20_swap) C++17
13 / 100
167 ms 12448 KB
#include "swap.h"
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAXN = 100005;
 
struct node {
    int endP[2], par, size, val;
} comp[MAXN];
 
int wpar[MAXN], depth[MAXN];
vector <int> adj[MAXN];
 
int root(int u) {
    while (comp[u].par >= 0) u = comp[u].par;
    return u;
}
 
bool join(int u, int v, int w) {
    int x = root(u), y = root(v);
    if (x == y) {
        if (comp[x].val < 0) comp[x].val = w;
        return false;
    }
    if (comp[x].size < comp[y].size) {
        swap(x, y); swap(u, v);
    }
    comp[x].size += comp[y].size; comp[y].par = x;
    wpar[y] = w; adj[x].push_back(y);
    if (comp[x].val < 0 && comp[y].val < 0 &&
    (u == comp[x].endP[0] || u == comp[x].endP[1]) &&
    (v == comp[y].endP[0] || v == comp[y].endP[1])) {
        if (u == comp[x].endP[0])
            comp[x].endP[0] = comp[x].endP[1];
        if (v == comp[y].endP[0])
            comp[x].endP[1] = comp[y].endP[1];
        else comp[x].endP[1] = comp[y].endP[0];
    } else if (comp[x].val < 0) comp[x].val = w;
    return true;
}
 
void DFS(int u) {
    for (int v : adj[u]) {
        depth[v] = depth[u] + 1; DFS(v);
    }
}
 
void init(int N, int M, vector <int> U,
vector <int> V, vector <int> W) {
    vector <int> sorted(M);
    iota(sorted.begin(), sorted.end(), 0);
    sort(sorted.begin(), sorted.end(),
    [&](int i, int j) {return W[i] < W[j];});
    for (int i = 0; i < N; i++) {
        comp[i].endP[0] = comp[i].endP[1] = i;
        comp[i].par = -1; comp[i].size = 1;
        comp[i].val = -1;
    }
    for (int i : sorted) join(U[i], V[i], W[i]);
    for (int i = 0; i < N; i++)
        if (comp[i].par < 0) DFS(i);
}
 
int getMinimumFuelCapacity(int u, int v) {
    if (root(u) != root(v)) return -1;
    int res = 0;
    while (u != v) {
        if (depth[u] < depth[v]) swap(u, v);
        res = max(res, wpar[u]); u = comp[u].par;
    }
    while (u >= 0 && comp[u].val < 0)
        u = comp[u].par;
    if (u < 0) return -1;
    return max(res, comp[u].val);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2656 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 3 ms 2640 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 52 ms 8136 KB Output is correct
10 Correct 66 ms 9364 KB Output is correct
11 Correct 64 ms 9252 KB Output is correct
12 Correct 70 ms 9668 KB Output is correct
13 Correct 53 ms 8832 KB Output is correct
14 Correct 60 ms 8244 KB Output is correct
15 Correct 163 ms 10944 KB Output is correct
16 Correct 159 ms 10824 KB Output is correct
17 Correct 163 ms 11228 KB Output is correct
18 Correct 124 ms 10432 KB Output is correct
19 Correct 82 ms 7356 KB Output is correct
20 Correct 167 ms 12068 KB Output is correct
21 Correct 163 ms 12084 KB Output is correct
22 Correct 167 ms 12448 KB Output is correct
23 Correct 134 ms 11664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 113 ms 11120 KB Output is correct
4 Correct 116 ms 11160 KB Output is correct
5 Correct 124 ms 11432 KB Output is correct
6 Correct 115 ms 11172 KB Output is correct
7 Correct 124 ms 11324 KB Output is correct
8 Correct 119 ms 11276 KB Output is correct
9 Correct 118 ms 11296 KB Output is correct
10 Correct 116 ms 11192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2656 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 3 ms 2640 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2672 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Incorrect 3 ms 2636 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2656 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 3 ms 2640 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 52 ms 8136 KB Output is correct
11 Correct 66 ms 9364 KB Output is correct
12 Correct 64 ms 9252 KB Output is correct
13 Correct 70 ms 9668 KB Output is correct
14 Correct 53 ms 8832 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2672 KB Output is correct
17 Correct 3 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Incorrect 3 ms 2636 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2656 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 3 ms 2640 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 52 ms 8136 KB Output is correct
10 Correct 66 ms 9364 KB Output is correct
11 Correct 64 ms 9252 KB Output is correct
12 Correct 70 ms 9668 KB Output is correct
13 Correct 53 ms 8832 KB Output is correct
14 Correct 60 ms 8244 KB Output is correct
15 Correct 163 ms 10944 KB Output is correct
16 Correct 159 ms 10824 KB Output is correct
17 Correct 163 ms 11228 KB Output is correct
18 Correct 124 ms 10432 KB Output is correct
19 Correct 113 ms 11120 KB Output is correct
20 Correct 116 ms 11160 KB Output is correct
21 Correct 124 ms 11432 KB Output is correct
22 Correct 115 ms 11172 KB Output is correct
23 Correct 124 ms 11324 KB Output is correct
24 Correct 119 ms 11276 KB Output is correct
25 Correct 118 ms 11296 KB Output is correct
26 Correct 116 ms 11192 KB Output is correct
27 Correct 2 ms 2636 KB Output is correct
28 Correct 2 ms 2672 KB Output is correct
29 Correct 3 ms 2636 KB Output is correct
30 Correct 2 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Incorrect 3 ms 2636 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2656 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 3 ms 2640 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 52 ms 8136 KB Output is correct
11 Correct 66 ms 9364 KB Output is correct
12 Correct 64 ms 9252 KB Output is correct
13 Correct 70 ms 9668 KB Output is correct
14 Correct 53 ms 8832 KB Output is correct
15 Correct 60 ms 8244 KB Output is correct
16 Correct 163 ms 10944 KB Output is correct
17 Correct 159 ms 10824 KB Output is correct
18 Correct 163 ms 11228 KB Output is correct
19 Correct 124 ms 10432 KB Output is correct
20 Correct 113 ms 11120 KB Output is correct
21 Correct 116 ms 11160 KB Output is correct
22 Correct 124 ms 11432 KB Output is correct
23 Correct 115 ms 11172 KB Output is correct
24 Correct 124 ms 11324 KB Output is correct
25 Correct 119 ms 11276 KB Output is correct
26 Correct 118 ms 11296 KB Output is correct
27 Correct 116 ms 11192 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 2 ms 2672 KB Output is correct
30 Correct 3 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 2 ms 2636 KB Output is correct
33 Incorrect 3 ms 2636 KB Output isn't correct
34 Halted 0 ms 0 KB -