답안 #683242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683242 2023-01-18T02:51:33 Z Nursik 자매 도시 (APIO20_swap) C++14
100 / 100
468 ms 133164 KB
#include "swap.h"

#include <stdio.h>
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define mp make_pair
#define f first
#define s second
#define pb push_back

const int maxn = 3e6 + 200;

int n, m;
int timer, p[maxn], sz[maxn], is[maxn], lst[maxn], deg[maxn], tin[maxn], tout[maxn], up[20][maxn], ans[maxn];
vector<pair<int, pair<int, int>>> kektor;
vector<int> g[maxn];
int get(int v){
    if (v == p[v])
        return v;
    return p[v] = get(p[v]);
}
bool upper(int a, int b){
    return (tin[a] <= tin[b] && tout[a] >= tout[b]);
}
int lca(int a, int b){
    if (upper(a, b))
        return a;
    if (upper(b, a))
        return b;
    for (int i = 19; i >= 0; --i){
        if (up[i][a] > 0 && !upper(up[i][a], b)){
            a = up[i][a];
        }
    }
    return up[0][a];
}
void dfs(int v, int par, int last){
    up[0][v] = par, tin[v] = ++timer;
    for (int i = 1; i <= 19; ++i){
        if (up[i - 1][v] == -1){
            up[i][v] = -1;
            continue;
        }
        up[i][v] = up[i - 1][up[i - 1][v]];
    }
    if (is[v] > 0 && v >= n){
        last = v;
    }
   // cout << "st\n";
   // cout << v << " " << last << '\n';
    ans[v] = last;
    for (auto to : g[v]){
        if (to != par){
            dfs(to, v, last);
        }
    }
    tout[v] = ++timer;
}
void init(int N, int M, vector<int> u, vector<int> v, vector<int> w) {
    n = N;
    m = M;
    for (int i = 0; i < m; ++i){
        int x = u[i], y = v[i];
        kektor.pb(mp(w[i], mp(x, y)));
    }
    sort(kektor.begin(), kektor.end());
    for (int i = 0; i < n + m; ++i){
        p[i] = i, sz[i] = 1, is[i] = 0;
    }
    int uk = n;
    for (int i = 0; i < m; ++i){
        pair<int, pair<int, int>> cur = kektor[i];
        int cost = cur.f, x = cur.s.f, y = cur.s.s;
        int r = get(x), r2 = get(y);
        deg[x] += 1, deg[y] += 1;
        if (r == r2){
            g[uk].pb(r);
            g[r].pb(uk);
            lst[uk] = cost;
            is[uk] |= 1;
            p[r] = uk;
        }
        else{
            g[uk].pb(r);
            g[r].pb(uk);
            g[uk].pb(r2);
            g[r2].pb(uk);
            lst[uk] = cost;
            is[uk] |= (is[r] | is[r2]);
            is[uk] |= (deg[x] >= 3);
            is[uk] |= (deg[y] >= 3);
            p[r] = uk, p[r2] = uk;
        }
        lst[uk] = cost;
        uk += 1;
    }
    dfs(n + m - 1, -1, -1);
}
int getMinimumFuelCapacity(int x, int y) {
    int lc = lca(x, y);
    if (ans[lc] == -1)
        return -1;
   // cout << lc << '\n';
    return lst[ans[lc]];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 70904 KB Output is correct
2 Correct 32 ms 70964 KB Output is correct
3 Correct 32 ms 70952 KB Output is correct
4 Correct 33 ms 71024 KB Output is correct
5 Correct 34 ms 71360 KB Output is correct
6 Correct 34 ms 71128 KB Output is correct
7 Correct 33 ms 71352 KB Output is correct
8 Correct 33 ms 71252 KB Output is correct
9 Correct 153 ms 96856 KB Output is correct
10 Correct 175 ms 102680 KB Output is correct
11 Correct 185 ms 102336 KB Output is correct
12 Correct 192 ms 103928 KB Output is correct
13 Correct 151 ms 107084 KB Output is correct
14 Correct 151 ms 97232 KB Output is correct
15 Correct 255 ms 106960 KB Output is correct
16 Correct 236 ms 106052 KB Output is correct
17 Correct 266 ms 108096 KB Output is correct
18 Correct 335 ms 111128 KB Output is correct
19 Correct 102 ms 81204 KB Output is correct
20 Correct 267 ms 108112 KB Output is correct
21 Correct 257 ms 107296 KB Output is correct
22 Correct 262 ms 109384 KB Output is correct
23 Correct 355 ms 112536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 70904 KB Output is correct
2 Correct 32 ms 70964 KB Output is correct
3 Correct 351 ms 113024 KB Output is correct
4 Correct 355 ms 114696 KB Output is correct
5 Correct 399 ms 113892 KB Output is correct
6 Correct 377 ms 114600 KB Output is correct
7 Correct 351 ms 114372 KB Output is correct
8 Correct 347 ms 112732 KB Output is correct
9 Correct 343 ms 114028 KB Output is correct
10 Correct 330 ms 112436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 70904 KB Output is correct
2 Correct 32 ms 70964 KB Output is correct
3 Correct 32 ms 70952 KB Output is correct
4 Correct 33 ms 71024 KB Output is correct
5 Correct 34 ms 71360 KB Output is correct
6 Correct 34 ms 71128 KB Output is correct
7 Correct 33 ms 71352 KB Output is correct
8 Correct 33 ms 71252 KB Output is correct
9 Correct 35 ms 70856 KB Output is correct
10 Correct 39 ms 71264 KB Output is correct
11 Correct 38 ms 71268 KB Output is correct
12 Correct 36 ms 71212 KB Output is correct
13 Correct 45 ms 71116 KB Output is correct
14 Correct 41 ms 71160 KB Output is correct
15 Correct 37 ms 71272 KB Output is correct
16 Correct 39 ms 71244 KB Output is correct
17 Correct 42 ms 71264 KB Output is correct
18 Correct 40 ms 71264 KB Output is correct
19 Correct 42 ms 71268 KB Output is correct
20 Correct 41 ms 71280 KB Output is correct
21 Correct 36 ms 71304 KB Output is correct
22 Correct 36 ms 71412 KB Output is correct
23 Correct 36 ms 71124 KB Output is correct
24 Correct 36 ms 71468 KB Output is correct
25 Correct 38 ms 71428 KB Output is correct
26 Correct 42 ms 71508 KB Output is correct
27 Correct 39 ms 71244 KB Output is correct
28 Correct 43 ms 71436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 70856 KB Output is correct
2 Correct 31 ms 70904 KB Output is correct
3 Correct 32 ms 70964 KB Output is correct
4 Correct 32 ms 70952 KB Output is correct
5 Correct 33 ms 71024 KB Output is correct
6 Correct 34 ms 71360 KB Output is correct
7 Correct 34 ms 71128 KB Output is correct
8 Correct 33 ms 71352 KB Output is correct
9 Correct 33 ms 71252 KB Output is correct
10 Correct 153 ms 96856 KB Output is correct
11 Correct 175 ms 102680 KB Output is correct
12 Correct 185 ms 102336 KB Output is correct
13 Correct 192 ms 103928 KB Output is correct
14 Correct 151 ms 107084 KB Output is correct
15 Correct 39 ms 71264 KB Output is correct
16 Correct 38 ms 71268 KB Output is correct
17 Correct 36 ms 71212 KB Output is correct
18 Correct 45 ms 71116 KB Output is correct
19 Correct 41 ms 71160 KB Output is correct
20 Correct 37 ms 71272 KB Output is correct
21 Correct 39 ms 71244 KB Output is correct
22 Correct 42 ms 71264 KB Output is correct
23 Correct 40 ms 71264 KB Output is correct
24 Correct 42 ms 71268 KB Output is correct
25 Correct 41 ms 71280 KB Output is correct
26 Correct 36 ms 71304 KB Output is correct
27 Correct 36 ms 71412 KB Output is correct
28 Correct 36 ms 71124 KB Output is correct
29 Correct 36 ms 71468 KB Output is correct
30 Correct 38 ms 71428 KB Output is correct
31 Correct 42 ms 71508 KB Output is correct
32 Correct 39 ms 71244 KB Output is correct
33 Correct 43 ms 71436 KB Output is correct
34 Correct 48 ms 75432 KB Output is correct
35 Correct 181 ms 103716 KB Output is correct
36 Correct 225 ms 103712 KB Output is correct
37 Correct 184 ms 103744 KB Output is correct
38 Correct 182 ms 103232 KB Output is correct
39 Correct 184 ms 103084 KB Output is correct
40 Correct 165 ms 100412 KB Output is correct
41 Correct 202 ms 103896 KB Output is correct
42 Correct 182 ms 103720 KB Output is correct
43 Correct 146 ms 107768 KB Output is correct
44 Correct 188 ms 104064 KB Output is correct
45 Correct 192 ms 115924 KB Output is correct
46 Correct 196 ms 103676 KB Output is correct
47 Correct 194 ms 103768 KB Output is correct
48 Correct 181 ms 107868 KB Output is correct
49 Correct 128 ms 110856 KB Output is correct
50 Correct 117 ms 102264 KB Output is correct
51 Correct 168 ms 109740 KB Output is correct
52 Correct 230 ms 119720 KB Output is correct
53 Correct 273 ms 122748 KB Output is correct
54 Correct 266 ms 129420 KB Output is correct
55 Correct 148 ms 107456 KB Output is correct
56 Correct 236 ms 124216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 70904 KB Output is correct
2 Correct 32 ms 70964 KB Output is correct
3 Correct 32 ms 70952 KB Output is correct
4 Correct 33 ms 71024 KB Output is correct
5 Correct 34 ms 71360 KB Output is correct
6 Correct 34 ms 71128 KB Output is correct
7 Correct 33 ms 71352 KB Output is correct
8 Correct 33 ms 71252 KB Output is correct
9 Correct 153 ms 96856 KB Output is correct
10 Correct 175 ms 102680 KB Output is correct
11 Correct 185 ms 102336 KB Output is correct
12 Correct 192 ms 103928 KB Output is correct
13 Correct 151 ms 107084 KB Output is correct
14 Correct 151 ms 97232 KB Output is correct
15 Correct 255 ms 106960 KB Output is correct
16 Correct 236 ms 106052 KB Output is correct
17 Correct 266 ms 108096 KB Output is correct
18 Correct 335 ms 111128 KB Output is correct
19 Correct 351 ms 113024 KB Output is correct
20 Correct 355 ms 114696 KB Output is correct
21 Correct 399 ms 113892 KB Output is correct
22 Correct 377 ms 114600 KB Output is correct
23 Correct 351 ms 114372 KB Output is correct
24 Correct 347 ms 112732 KB Output is correct
25 Correct 343 ms 114028 KB Output is correct
26 Correct 330 ms 112436 KB Output is correct
27 Correct 39 ms 71264 KB Output is correct
28 Correct 38 ms 71268 KB Output is correct
29 Correct 36 ms 71212 KB Output is correct
30 Correct 45 ms 71116 KB Output is correct
31 Correct 41 ms 71160 KB Output is correct
32 Correct 37 ms 71272 KB Output is correct
33 Correct 39 ms 71244 KB Output is correct
34 Correct 42 ms 71264 KB Output is correct
35 Correct 40 ms 71264 KB Output is correct
36 Correct 48 ms 75432 KB Output is correct
37 Correct 181 ms 103716 KB Output is correct
38 Correct 225 ms 103712 KB Output is correct
39 Correct 184 ms 103744 KB Output is correct
40 Correct 182 ms 103232 KB Output is correct
41 Correct 184 ms 103084 KB Output is correct
42 Correct 165 ms 100412 KB Output is correct
43 Correct 202 ms 103896 KB Output is correct
44 Correct 182 ms 103720 KB Output is correct
45 Correct 146 ms 107768 KB Output is correct
46 Correct 188 ms 104064 KB Output is correct
47 Correct 59 ms 75580 KB Output is correct
48 Correct 276 ms 108728 KB Output is correct
49 Correct 267 ms 108584 KB Output is correct
50 Correct 290 ms 108744 KB Output is correct
51 Correct 259 ms 108336 KB Output is correct
52 Correct 276 ms 106432 KB Output is correct
53 Correct 208 ms 98620 KB Output is correct
54 Correct 277 ms 109388 KB Output is correct
55 Correct 271 ms 108688 KB Output is correct
56 Correct 385 ms 111756 KB Output is correct
57 Correct 308 ms 109564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 70856 KB Output is correct
2 Correct 31 ms 70904 KB Output is correct
3 Correct 32 ms 70964 KB Output is correct
4 Correct 32 ms 70952 KB Output is correct
5 Correct 33 ms 71024 KB Output is correct
6 Correct 34 ms 71360 KB Output is correct
7 Correct 34 ms 71128 KB Output is correct
8 Correct 33 ms 71352 KB Output is correct
9 Correct 33 ms 71252 KB Output is correct
10 Correct 153 ms 96856 KB Output is correct
11 Correct 175 ms 102680 KB Output is correct
12 Correct 185 ms 102336 KB Output is correct
13 Correct 192 ms 103928 KB Output is correct
14 Correct 151 ms 107084 KB Output is correct
15 Correct 151 ms 97232 KB Output is correct
16 Correct 255 ms 106960 KB Output is correct
17 Correct 236 ms 106052 KB Output is correct
18 Correct 266 ms 108096 KB Output is correct
19 Correct 335 ms 111128 KB Output is correct
20 Correct 351 ms 113024 KB Output is correct
21 Correct 355 ms 114696 KB Output is correct
22 Correct 399 ms 113892 KB Output is correct
23 Correct 377 ms 114600 KB Output is correct
24 Correct 351 ms 114372 KB Output is correct
25 Correct 347 ms 112732 KB Output is correct
26 Correct 343 ms 114028 KB Output is correct
27 Correct 330 ms 112436 KB Output is correct
28 Correct 39 ms 71264 KB Output is correct
29 Correct 38 ms 71268 KB Output is correct
30 Correct 36 ms 71212 KB Output is correct
31 Correct 45 ms 71116 KB Output is correct
32 Correct 41 ms 71160 KB Output is correct
33 Correct 37 ms 71272 KB Output is correct
34 Correct 39 ms 71244 KB Output is correct
35 Correct 42 ms 71264 KB Output is correct
36 Correct 40 ms 71264 KB Output is correct
37 Correct 48 ms 75432 KB Output is correct
38 Correct 181 ms 103716 KB Output is correct
39 Correct 225 ms 103712 KB Output is correct
40 Correct 184 ms 103744 KB Output is correct
41 Correct 182 ms 103232 KB Output is correct
42 Correct 184 ms 103084 KB Output is correct
43 Correct 165 ms 100412 KB Output is correct
44 Correct 202 ms 103896 KB Output is correct
45 Correct 182 ms 103720 KB Output is correct
46 Correct 146 ms 107768 KB Output is correct
47 Correct 188 ms 104064 KB Output is correct
48 Correct 59 ms 75580 KB Output is correct
49 Correct 276 ms 108728 KB Output is correct
50 Correct 267 ms 108584 KB Output is correct
51 Correct 290 ms 108744 KB Output is correct
52 Correct 259 ms 108336 KB Output is correct
53 Correct 276 ms 106432 KB Output is correct
54 Correct 208 ms 98620 KB Output is correct
55 Correct 277 ms 109388 KB Output is correct
56 Correct 271 ms 108688 KB Output is correct
57 Correct 385 ms 111756 KB Output is correct
58 Correct 308 ms 109564 KB Output is correct
59 Correct 102 ms 81204 KB Output is correct
60 Correct 267 ms 108112 KB Output is correct
61 Correct 257 ms 107296 KB Output is correct
62 Correct 262 ms 109384 KB Output is correct
63 Correct 355 ms 112536 KB Output is correct
64 Correct 42 ms 71268 KB Output is correct
65 Correct 41 ms 71280 KB Output is correct
66 Correct 36 ms 71304 KB Output is correct
67 Correct 36 ms 71412 KB Output is correct
68 Correct 36 ms 71124 KB Output is correct
69 Correct 36 ms 71468 KB Output is correct
70 Correct 38 ms 71428 KB Output is correct
71 Correct 42 ms 71508 KB Output is correct
72 Correct 39 ms 71244 KB Output is correct
73 Correct 43 ms 71436 KB Output is correct
74 Correct 192 ms 115924 KB Output is correct
75 Correct 196 ms 103676 KB Output is correct
76 Correct 194 ms 103768 KB Output is correct
77 Correct 181 ms 107868 KB Output is correct
78 Correct 128 ms 110856 KB Output is correct
79 Correct 117 ms 102264 KB Output is correct
80 Correct 168 ms 109740 KB Output is correct
81 Correct 230 ms 119720 KB Output is correct
82 Correct 273 ms 122748 KB Output is correct
83 Correct 266 ms 129420 KB Output is correct
84 Correct 148 ms 107456 KB Output is correct
85 Correct 236 ms 124216 KB Output is correct
86 Correct 118 ms 87604 KB Output is correct
87 Correct 280 ms 108684 KB Output is correct
88 Correct 265 ms 108580 KB Output is correct
89 Correct 389 ms 110880 KB Output is correct
90 Correct 238 ms 117168 KB Output is correct
91 Correct 252 ms 114248 KB Output is correct
92 Correct 366 ms 113360 KB Output is correct
93 Correct 414 ms 123696 KB Output is correct
94 Correct 468 ms 127256 KB Output is correct
95 Correct 388 ms 133164 KB Output is correct
96 Correct 366 ms 112096 KB Output is correct
97 Correct 457 ms 119804 KB Output is correct