Submission #395219

# Submission time Handle Problem Language Result Execution time Memory
395219 2021-04-28T02:55:16 Z syl123456 Swapping Cities (APIO20_swap) C++17
100 / 100
267 ms 24360 KB
#include "swap.h"
#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
using namespace std;
typedef pair<int, int> pi;
typedef pair<int, pi> pp;
const int inf = 1 << 30;

template<typename T1, typename T2>
ostream& operator << (ostream &i, pair<T1, T2> j) {
    return i << j.first << ' ' << j.second;
}

vector<pi> p, now;//pa, _t
vector<int> r, t;//rank
map<pi, pi> mp;//[ver, _t] : [l, r]

int find(int i) {
    return p[i].first == i ? i : find(p[i].first);
}

void init(int N, int M,
          std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    p.clear(), now.clear(), r.clear(), mp.clear();
    for (int i = 0; i < N; ++i) {
        p.emplace_back(i, inf);
        now.emplace_back(i, i);
        r.push_back(0);
        t.push_back(inf);
    }
    vector<pp> e;
    for (int i = 0; i < M; ++i) e.emplace_back(W[i], pi(U[i], V[i]));
    sort(all(e));
    for (pp i : e) {
        int x = find(i.second.first), y = find(i.second.second);
        if (x == y) {
            if (t[x] == inf)
                t[x] = i.first, mp[{x, t[x]}] = now[x] = {-1, -1};
        }
        else {
            if ((i.second.first != now[x].first && i.second.first != now[x].second) || (i.second.second != now[y].first && i.second.second != now[y].second)) {
                now[x] = now[y] = {-1, -1};
                t[x] = min(t[x], i.first);
                t[y] = min(t[y], i.first);
            }
            else
                now[x] = now[y] = pi(now[x].first ^ now[x].second ^ i.second.first, now[y].first ^ now[y].second ^ i.second.second);
            if (r[x] < r[y]) swap(x, y);
            else if (r[x] == r[y]) ++r[x];
            p[y] = {x, i.first};
            mp[{x, i.first}] = now[x];
        }
    }
}

int getMinimumFuelCapacity(int X, int Y) {
    int ans = 0;
    while (X != Y) {
        ans = min(p[X].second, p[Y].second);
        while (p[X].second <= ans) X = p[X].first;
        while (p[Y].second <= ans) Y = p[Y].first;
    }
    while (p[X].first != X && t[X] == inf) X = p[X].first;
    return t[X] == inf ? -1 : max(ans, t[X]);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 80 ms 11564 KB Output is correct
10 Correct 129 ms 13548 KB Output is correct
11 Correct 139 ms 13376 KB Output is correct
12 Correct 113 ms 13996 KB Output is correct
13 Correct 78 ms 14096 KB Output is correct
14 Correct 88 ms 11640 KB Output is correct
15 Correct 203 ms 17324 KB Output is correct
16 Correct 200 ms 16428 KB Output is correct
17 Correct 222 ms 17196 KB Output is correct
18 Correct 149 ms 17176 KB Output is correct
19 Correct 92 ms 7400 KB Output is correct
20 Correct 236 ms 17096 KB Output is correct
21 Correct 199 ms 17128 KB Output is correct
22 Correct 217 ms 17900 KB Output is correct
23 Correct 151 ms 17788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 153 ms 15372 KB Output is correct
4 Correct 145 ms 18048 KB Output is correct
5 Correct 143 ms 18072 KB Output is correct
6 Correct 158 ms 18048 KB Output is correct
7 Correct 141 ms 18092 KB Output is correct
8 Correct 138 ms 17580 KB Output is correct
9 Correct 146 ms 17928 KB Output is correct
10 Correct 139 ms 17580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 80 ms 11564 KB Output is correct
11 Correct 129 ms 13548 KB Output is correct
12 Correct 139 ms 13376 KB Output is correct
13 Correct 113 ms 13996 KB Output is correct
14 Correct 78 ms 14096 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 12 ms 2148 KB Output is correct
35 Correct 117 ms 14148 KB Output is correct
36 Correct 108 ms 14220 KB Output is correct
37 Correct 107 ms 14104 KB Output is correct
38 Correct 111 ms 14004 KB Output is correct
39 Correct 128 ms 13912 KB Output is correct
40 Correct 105 ms 12888 KB Output is correct
41 Correct 110 ms 14096 KB Output is correct
42 Correct 110 ms 14200 KB Output is correct
43 Correct 79 ms 14128 KB Output is correct
44 Correct 132 ms 14224 KB Output is correct
45 Correct 107 ms 14032 KB Output is correct
46 Correct 139 ms 14224 KB Output is correct
47 Correct 116 ms 14304 KB Output is correct
48 Correct 102 ms 14292 KB Output is correct
49 Correct 73 ms 8916 KB Output is correct
50 Correct 59 ms 6828 KB Output is correct
51 Correct 88 ms 11880 KB Output is correct
52 Correct 150 ms 16356 KB Output is correct
53 Correct 195 ms 19032 KB Output is correct
54 Correct 162 ms 17712 KB Output is correct
55 Correct 75 ms 14124 KB Output is correct
56 Correct 155 ms 16864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 80 ms 11564 KB Output is correct
10 Correct 129 ms 13548 KB Output is correct
11 Correct 139 ms 13376 KB Output is correct
12 Correct 113 ms 13996 KB Output is correct
13 Correct 78 ms 14096 KB Output is correct
14 Correct 88 ms 11640 KB Output is correct
15 Correct 203 ms 17324 KB Output is correct
16 Correct 200 ms 16428 KB Output is correct
17 Correct 222 ms 17196 KB Output is correct
18 Correct 149 ms 17176 KB Output is correct
19 Correct 153 ms 15372 KB Output is correct
20 Correct 145 ms 18048 KB Output is correct
21 Correct 143 ms 18072 KB Output is correct
22 Correct 158 ms 18048 KB Output is correct
23 Correct 141 ms 18092 KB Output is correct
24 Correct 138 ms 17580 KB Output is correct
25 Correct 146 ms 17928 KB Output is correct
26 Correct 139 ms 17580 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 12 ms 2148 KB Output is correct
37 Correct 117 ms 14148 KB Output is correct
38 Correct 108 ms 14220 KB Output is correct
39 Correct 107 ms 14104 KB Output is correct
40 Correct 111 ms 14004 KB Output is correct
41 Correct 128 ms 13912 KB Output is correct
42 Correct 105 ms 12888 KB Output is correct
43 Correct 110 ms 14096 KB Output is correct
44 Correct 110 ms 14200 KB Output is correct
45 Correct 79 ms 14128 KB Output is correct
46 Correct 132 ms 14224 KB Output is correct
47 Correct 19 ms 2476 KB Output is correct
48 Correct 205 ms 18156 KB Output is correct
49 Correct 209 ms 18240 KB Output is correct
50 Correct 200 ms 18220 KB Output is correct
51 Correct 202 ms 18064 KB Output is correct
52 Correct 207 ms 17340 KB Output is correct
53 Correct 154 ms 15000 KB Output is correct
54 Correct 222 ms 18892 KB Output is correct
55 Correct 209 ms 18220 KB Output is correct
56 Correct 156 ms 18096 KB Output is correct
57 Correct 224 ms 18996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 80 ms 11564 KB Output is correct
11 Correct 129 ms 13548 KB Output is correct
12 Correct 139 ms 13376 KB Output is correct
13 Correct 113 ms 13996 KB Output is correct
14 Correct 78 ms 14096 KB Output is correct
15 Correct 88 ms 11640 KB Output is correct
16 Correct 203 ms 17324 KB Output is correct
17 Correct 200 ms 16428 KB Output is correct
18 Correct 222 ms 17196 KB Output is correct
19 Correct 149 ms 17176 KB Output is correct
20 Correct 153 ms 15372 KB Output is correct
21 Correct 145 ms 18048 KB Output is correct
22 Correct 143 ms 18072 KB Output is correct
23 Correct 158 ms 18048 KB Output is correct
24 Correct 141 ms 18092 KB Output is correct
25 Correct 138 ms 17580 KB Output is correct
26 Correct 146 ms 17928 KB Output is correct
27 Correct 139 ms 17580 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 12 ms 2148 KB Output is correct
38 Correct 117 ms 14148 KB Output is correct
39 Correct 108 ms 14220 KB Output is correct
40 Correct 107 ms 14104 KB Output is correct
41 Correct 111 ms 14004 KB Output is correct
42 Correct 128 ms 13912 KB Output is correct
43 Correct 105 ms 12888 KB Output is correct
44 Correct 110 ms 14096 KB Output is correct
45 Correct 110 ms 14200 KB Output is correct
46 Correct 79 ms 14128 KB Output is correct
47 Correct 132 ms 14224 KB Output is correct
48 Correct 19 ms 2476 KB Output is correct
49 Correct 205 ms 18156 KB Output is correct
50 Correct 209 ms 18240 KB Output is correct
51 Correct 200 ms 18220 KB Output is correct
52 Correct 202 ms 18064 KB Output is correct
53 Correct 207 ms 17340 KB Output is correct
54 Correct 154 ms 15000 KB Output is correct
55 Correct 222 ms 18892 KB Output is correct
56 Correct 209 ms 18220 KB Output is correct
57 Correct 156 ms 18096 KB Output is correct
58 Correct 224 ms 18996 KB Output is correct
59 Correct 92 ms 7400 KB Output is correct
60 Correct 236 ms 17096 KB Output is correct
61 Correct 199 ms 17128 KB Output is correct
62 Correct 217 ms 17900 KB Output is correct
63 Correct 151 ms 17788 KB Output is correct
64 Correct 1 ms 336 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 332 KB Output is correct
67 Correct 2 ms 332 KB Output is correct
68 Correct 1 ms 332 KB Output is correct
69 Correct 2 ms 460 KB Output is correct
70 Correct 2 ms 460 KB Output is correct
71 Correct 2 ms 460 KB Output is correct
72 Correct 1 ms 332 KB Output is correct
73 Correct 2 ms 460 KB Output is correct
74 Correct 107 ms 14032 KB Output is correct
75 Correct 139 ms 14224 KB Output is correct
76 Correct 116 ms 14304 KB Output is correct
77 Correct 102 ms 14292 KB Output is correct
78 Correct 73 ms 8916 KB Output is correct
79 Correct 59 ms 6828 KB Output is correct
80 Correct 88 ms 11880 KB Output is correct
81 Correct 150 ms 16356 KB Output is correct
82 Correct 195 ms 19032 KB Output is correct
83 Correct 162 ms 17712 KB Output is correct
84 Correct 75 ms 14124 KB Output is correct
85 Correct 155 ms 16864 KB Output is correct
86 Correct 57 ms 6700 KB Output is correct
87 Correct 208 ms 18200 KB Output is correct
88 Correct 204 ms 18240 KB Output is correct
89 Correct 173 ms 17712 KB Output is correct
90 Correct 149 ms 13752 KB Output is correct
91 Correct 155 ms 13740 KB Output is correct
92 Correct 170 ms 16560 KB Output is correct
93 Correct 259 ms 21848 KB Output is correct
94 Correct 255 ms 24360 KB Output is correct
95 Correct 267 ms 23808 KB Output is correct
96 Correct 150 ms 18072 KB Output is correct
97 Correct 212 ms 20528 KB Output is correct