답안 #576514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576514 2022-06-13T07:06:18 Z ParsaEs 자매 도시 (APIO20_swap) C++14
100 / 100
318 ms 31660 KB
//InTheNameOfGOD
//PRS;)
#include<bits/stdc++.h>
#include "swap.h"
#define rep(i, l, r) for(ll i = l; i < r; i++)
#define min(x, y) (x < y ? x : y)
#define max(x, y) (x > y ? x : y)
#define pb push_back
#define X first
#define Y second
typedef int ll;
using namespace std;
typedef pair<ll, ll> pl;
typedef pair<ll, pl> pi;
constexpr ll inf = 2e9, xm = 2e5 + 5, xn = 1e5 + 5;
vector<pl> p[xn];
vector<ll> g[xn];
pi e[xm];
ll ans[xn], d[xn], n, m;
void init(ll N, ll M, vector<ll> U, vector<ll> V, vector<ll> W)
{
    n = N, m = M;
    rep(i, 0, N) p[i].pb({0, i}), g[i].pb(i), ans[i] = inf;
    rep(i, 0, M) e[i] = {W[i], {U[i], V[i]}};
    sort(e, e + M);
    rep(i, 0, M)
    {
        ll v = e[i].X, x = e[i].Y.X, y = e[i].Y.Y;
        ll x1 = p[x].back().Y, y1 = p[y].back().Y;
        if(x1 == y1)
        {
            ans[x1] = min(ans[x1], v);
            continue;
        }
        if(g[x1].size() < g[y1].size()) swap(x1, y1), swap(x, y);
        ans[x1] = min(ans[x1], max(ans[y1], v)), d[x]++, d[y]++;
        if(d[x] > 2 || d[y] > 2) ans[x1] = min(ans[x1], v);
        for(ll u : g[y1]) p[u].pb({v, x1}), g[x1].pb(u);
    }
}
ll getMinimumFuelCapacity(ll x, ll y)
{
    ll i = p[x].size(), j = p[y].size(), ret = inf;
    i--, j--;
    while(i >= 0 && j >= 0 &&p[x][i].Y == p[y][j].Y)
        ret = min(ret, max(ans[p[x][i].Y], max(p[x][i].X, p[y][j].X))), i--, j--;
    return (ret >= inf ? -1 : ret);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 4 ms 5204 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 128 ms 21492 KB Output is correct
10 Correct 173 ms 24904 KB Output is correct
11 Correct 144 ms 24520 KB Output is correct
12 Correct 168 ms 25776 KB Output is correct
13 Correct 113 ms 18484 KB Output is correct
14 Correct 148 ms 21604 KB Output is correct
15 Correct 221 ms 27240 KB Output is correct
16 Correct 199 ms 26484 KB Output is correct
17 Correct 242 ms 28028 KB Output is correct
18 Correct 179 ms 20184 KB Output is correct
19 Correct 61 ms 11520 KB Output is correct
20 Correct 236 ms 28432 KB Output is correct
21 Correct 223 ms 27800 KB Output is correct
22 Correct 253 ms 29100 KB Output is correct
23 Correct 153 ms 21672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 161 ms 18488 KB Output is correct
4 Correct 176 ms 18860 KB Output is correct
5 Correct 138 ms 18788 KB Output is correct
6 Correct 133 ms 18788 KB Output is correct
7 Correct 155 ms 18936 KB Output is correct
8 Correct 153 ms 18428 KB Output is correct
9 Correct 129 ms 18756 KB Output is correct
10 Correct 147 ms 18416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 4 ms 5204 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5128 KB Output is correct
16 Correct 4 ms 5076 KB Output is correct
17 Correct 4 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 5 ms 5076 KB Output is correct
21 Correct 4 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 4 ms 5204 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 5 ms 5204 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 128 ms 21492 KB Output is correct
11 Correct 173 ms 24904 KB Output is correct
12 Correct 144 ms 24520 KB Output is correct
13 Correct 168 ms 25776 KB Output is correct
14 Correct 113 ms 18484 KB Output is correct
15 Correct 4 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 4 ms 5076 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 4 ms 5128 KB Output is correct
21 Correct 4 ms 5076 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 5 ms 5076 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 4 ms 5204 KB Output is correct
30 Correct 4 ms 5076 KB Output is correct
31 Correct 5 ms 5204 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 15 ms 7420 KB Output is correct
35 Correct 202 ms 25636 KB Output is correct
36 Correct 210 ms 25512 KB Output is correct
37 Correct 156 ms 25032 KB Output is correct
38 Correct 167 ms 24132 KB Output is correct
39 Correct 201 ms 23676 KB Output is correct
40 Correct 142 ms 21800 KB Output is correct
41 Correct 170 ms 26104 KB Output is correct
42 Correct 173 ms 26084 KB Output is correct
43 Correct 125 ms 17592 KB Output is correct
44 Correct 216 ms 23440 KB Output is correct
45 Correct 135 ms 18664 KB Output is correct
46 Correct 181 ms 25376 KB Output is correct
47 Correct 165 ms 22048 KB Output is correct
48 Correct 157 ms 19356 KB Output is correct
49 Correct 61 ms 10648 KB Output is correct
50 Correct 61 ms 10024 KB Output is correct
51 Correct 91 ms 16224 KB Output is correct
52 Correct 204 ms 26808 KB Output is correct
53 Correct 180 ms 22988 KB Output is correct
54 Correct 226 ms 29616 KB Output is correct
55 Correct 111 ms 17896 KB Output is correct
56 Correct 174 ms 21736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 4 ms 5204 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 128 ms 21492 KB Output is correct
10 Correct 173 ms 24904 KB Output is correct
11 Correct 144 ms 24520 KB Output is correct
12 Correct 168 ms 25776 KB Output is correct
13 Correct 113 ms 18484 KB Output is correct
14 Correct 148 ms 21604 KB Output is correct
15 Correct 221 ms 27240 KB Output is correct
16 Correct 199 ms 26484 KB Output is correct
17 Correct 242 ms 28028 KB Output is correct
18 Correct 179 ms 20184 KB Output is correct
19 Correct 161 ms 18488 KB Output is correct
20 Correct 176 ms 18860 KB Output is correct
21 Correct 138 ms 18788 KB Output is correct
22 Correct 133 ms 18788 KB Output is correct
23 Correct 155 ms 18936 KB Output is correct
24 Correct 153 ms 18428 KB Output is correct
25 Correct 129 ms 18756 KB Output is correct
26 Correct 147 ms 18416 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 4 ms 5076 KB Output is correct
30 Correct 3 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 4 ms 5128 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 15 ms 7420 KB Output is correct
37 Correct 202 ms 25636 KB Output is correct
38 Correct 210 ms 25512 KB Output is correct
39 Correct 156 ms 25032 KB Output is correct
40 Correct 167 ms 24132 KB Output is correct
41 Correct 201 ms 23676 KB Output is correct
42 Correct 142 ms 21800 KB Output is correct
43 Correct 170 ms 26104 KB Output is correct
44 Correct 173 ms 26084 KB Output is correct
45 Correct 125 ms 17592 KB Output is correct
46 Correct 216 ms 23440 KB Output is correct
47 Correct 18 ms 7636 KB Output is correct
48 Correct 225 ms 28448 KB Output is correct
49 Correct 236 ms 27756 KB Output is correct
50 Correct 249 ms 27596 KB Output is correct
51 Correct 205 ms 27076 KB Output is correct
52 Correct 212 ms 25464 KB Output is correct
53 Correct 147 ms 20536 KB Output is correct
54 Correct 225 ms 28664 KB Output is correct
55 Correct 274 ms 28968 KB Output is correct
56 Correct 152 ms 21000 KB Output is correct
57 Correct 264 ms 26396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 128 ms 21492 KB Output is correct
11 Correct 173 ms 24904 KB Output is correct
12 Correct 144 ms 24520 KB Output is correct
13 Correct 168 ms 25776 KB Output is correct
14 Correct 113 ms 18484 KB Output is correct
15 Correct 148 ms 21604 KB Output is correct
16 Correct 221 ms 27240 KB Output is correct
17 Correct 199 ms 26484 KB Output is correct
18 Correct 242 ms 28028 KB Output is correct
19 Correct 179 ms 20184 KB Output is correct
20 Correct 161 ms 18488 KB Output is correct
21 Correct 176 ms 18860 KB Output is correct
22 Correct 138 ms 18788 KB Output is correct
23 Correct 133 ms 18788 KB Output is correct
24 Correct 155 ms 18936 KB Output is correct
25 Correct 153 ms 18428 KB Output is correct
26 Correct 129 ms 18756 KB Output is correct
27 Correct 147 ms 18416 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 4 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 4 ms 5128 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 15 ms 7420 KB Output is correct
38 Correct 202 ms 25636 KB Output is correct
39 Correct 210 ms 25512 KB Output is correct
40 Correct 156 ms 25032 KB Output is correct
41 Correct 167 ms 24132 KB Output is correct
42 Correct 201 ms 23676 KB Output is correct
43 Correct 142 ms 21800 KB Output is correct
44 Correct 170 ms 26104 KB Output is correct
45 Correct 173 ms 26084 KB Output is correct
46 Correct 125 ms 17592 KB Output is correct
47 Correct 216 ms 23440 KB Output is correct
48 Correct 18 ms 7636 KB Output is correct
49 Correct 225 ms 28448 KB Output is correct
50 Correct 236 ms 27756 KB Output is correct
51 Correct 249 ms 27596 KB Output is correct
52 Correct 205 ms 27076 KB Output is correct
53 Correct 212 ms 25464 KB Output is correct
54 Correct 147 ms 20536 KB Output is correct
55 Correct 225 ms 28664 KB Output is correct
56 Correct 274 ms 28968 KB Output is correct
57 Correct 152 ms 21000 KB Output is correct
58 Correct 264 ms 26396 KB Output is correct
59 Correct 61 ms 11520 KB Output is correct
60 Correct 236 ms 28432 KB Output is correct
61 Correct 223 ms 27800 KB Output is correct
62 Correct 253 ms 29100 KB Output is correct
63 Correct 153 ms 21672 KB Output is correct
64 Correct 3 ms 5076 KB Output is correct
65 Correct 5 ms 5076 KB Output is correct
66 Correct 4 ms 5076 KB Output is correct
67 Correct 3 ms 5076 KB Output is correct
68 Correct 3 ms 5076 KB Output is correct
69 Correct 4 ms 5204 KB Output is correct
70 Correct 4 ms 5076 KB Output is correct
71 Correct 5 ms 5204 KB Output is correct
72 Correct 3 ms 5076 KB Output is correct
73 Correct 4 ms 5076 KB Output is correct
74 Correct 135 ms 18664 KB Output is correct
75 Correct 181 ms 25376 KB Output is correct
76 Correct 165 ms 22048 KB Output is correct
77 Correct 157 ms 19356 KB Output is correct
78 Correct 61 ms 10648 KB Output is correct
79 Correct 61 ms 10024 KB Output is correct
80 Correct 91 ms 16224 KB Output is correct
81 Correct 204 ms 26808 KB Output is correct
82 Correct 180 ms 22988 KB Output is correct
83 Correct 226 ms 29616 KB Output is correct
84 Correct 111 ms 17896 KB Output is correct
85 Correct 174 ms 21736 KB Output is correct
86 Correct 48 ms 10524 KB Output is correct
87 Correct 231 ms 27380 KB Output is correct
88 Correct 230 ms 27552 KB Output is correct
89 Correct 160 ms 20980 KB Output is correct
90 Correct 162 ms 13064 KB Output is correct
91 Correct 137 ms 13836 KB Output is correct
92 Correct 149 ms 19028 KB Output is correct
93 Correct 275 ms 28448 KB Output is correct
94 Correct 226 ms 25592 KB Output is correct
95 Correct 318 ms 31660 KB Output is correct
96 Correct 164 ms 20920 KB Output is correct
97 Correct 190 ms 23512 KB Output is correct