답안 #889008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889008 2023-12-18T15:16:49 Z dwuy 꿈 (IOI13_dreaming) C++14
47 / 100
48 ms 17744 KB
/// dwuy: _,\,,,_\,__,\,,_
#include "dreaming.h"
#include <bits/stdc++.h>

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
#define fi first
#define se second
#define endl "\n"
#define len(s) int32_t(s.length())
#define MASK(k)(1LL<<(k))
#define TASK ""

using namespace std;

typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;

const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MX = 100005;

struct DSU{
    int n;
    vector<int> e;

    DSU(int n=0){
        this->n = n;
        this->e.assign(n+5, -1);
    }

    int fp(int u){
        return e[u]<0? u : e[u] = fp(e[u]);
    }

    void unon(int u, int v){
        u = fp(u);
        v = fp(v);
        if(u == v) return;
        if(e[u] > e[v]) swap(u, v);
        e[u] += e[v];
        e[v] = u;
    }
};

int n, m, l;
vector<pii> G[MX];
int dp[MX];
int dpDown[MX];
int mnPath[MX];
pii pf[MX];
pii sf[MX];
DSU dsu;

void calc_dp_down(int u, int p){
    dpDown[u] = 0;
    for(pii &tmp: G[u]){
        int v, c; tie(v, c) = tmp;
        if(v == p) continue;
        calc_dp_down(v, u);
        dpDown[u] = max(dpDown[u], dpDown[v] + c);
    }
}

void calc_dp(int u, int p, int mx){
    pii best1 = {mx, p};
    pii best2 = {0, 0};
    for(pii &tmp: G[u]){
        int v, c; tie(v, c) = tmp;
        if(v == p) continue;
        int dis = dpDown[v] + c;
        if(dis >= best1.fi){
            best2 = best1;
            best1 = {dis, v};
        }
        else best2 = max(best2, {dis, v});
    }
    dp[u] = best1.fi;
    for(pii &tmp: G[u]){
        int v, c; tie(v, c) = tmp;
        if(v == p) continue;
        if(v == best1.se) calc_dp(v, u, best2.fi + c);
        else calc_dp(v, u, best1.fi + c);
    }
}

pii combine(pii a, pii b){
    if(a.fi < b.fi) swap(a, b);
    if(a.se > b.fi) return a;
    return {a.fi, b.fi};
}

int travelTime(int N, int M, int L, int A[], int B[], int C[]){
    tie(n, m, l) = {N, M, L};
    dsu = DSU(n);
    for(int i=0; i<m; i++){
        int u = A[i]; u++;
        int v = B[i]; v++;
        int c = C[i];
        G[u].push_back({v, c});
        G[v].push_back({u, c});
        dsu.unon(u, v);
    }
    memset(dpDown, -1, sizeof dpDown);
    memset(dp, -1, sizeof dp);
    for(int i=1; i<=n; i++) if(dpDown[i] == -1) calc_dp_down(i, 0);
    for(int i=1; i<=n; i++) if(dp[i] == -1) calc_dp(i, 0, 0);

    for(int i=0; i<=n+1; i++){
        pf[i] = {-1, -1};
        sf[i] = {-1, -1};
    }

    memset(mnPath, 0x3f, sizeof mnPath);
    for(int i=1; i<=n; i++){
        int root = dsu.fp(i);
        mnPath[root] = min(mnPath[root], dp[i]);
    }
    for(int i=1;  i<=n; i++) if(dsu.fp(i) != i) mnPath[i] = -1;

    for(int i=1; i<=n; i++){
        pf[i] = {mnPath[i], -1};
        pf[i] = combine(pf[i-1], pf[i]);
    }
    for(int i=n; i>=1; i--){
        if(dsu.fp(i) == i) sf[i] = {mnPath[i], -1};
        else sf[i] = {-1, -1};
        sf[i] = combine(sf[i+1], sf[i]);
    }
    int ans = INF;
    for(int i=1; i<=n; i++) if(dsu.fp(i) == i){
        pii best = combine(pf[i-1], sf[i+1]);
        if(best.fi != -1 && best.se != -1) ans = min(ans, max(best.fi + best.se + l + l, best.fi + mnPath[i] + l));
        else ans = min(ans, best.fi + mnPath[i] + l);
    }
    for(int i=1; i<=n; i++) ans = max(ans, dp[i]);
    return ans;
}



# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 13652 KB Output is correct
2 Correct 33 ms 13396 KB Output is correct
3 Correct 22 ms 12636 KB Output is correct
4 Correct 6 ms 7516 KB Output is correct
5 Correct 5 ms 7004 KB Output is correct
6 Correct 9 ms 8028 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 17 ms 9560 KB Output is correct
9 Correct 22 ms 11364 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 30 ms 11604 KB Output is correct
12 Correct 34 ms 12636 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6524 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6312 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6324 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 13652 KB Output is correct
2 Correct 33 ms 13396 KB Output is correct
3 Correct 22 ms 12636 KB Output is correct
4 Correct 6 ms 7516 KB Output is correct
5 Correct 5 ms 7004 KB Output is correct
6 Correct 9 ms 8028 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 17 ms 9560 KB Output is correct
9 Correct 22 ms 11364 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 30 ms 11604 KB Output is correct
12 Correct 34 ms 12636 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6524 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6312 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 2 ms 6324 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 32 ms 13860 KB Output is correct
40 Correct 31 ms 13404 KB Output is correct
41 Correct 22 ms 12636 KB Output is correct
42 Correct 6 ms 7512 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6536 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 38 ms 10960 KB Output is correct
58 Correct 41 ms 10856 KB Output is correct
59 Correct 39 ms 10844 KB Output is correct
60 Correct 39 ms 10844 KB Output is correct
61 Correct 40 ms 10780 KB Output is correct
62 Correct 39 ms 10844 KB Output is correct
63 Correct 36 ms 10576 KB Output is correct
64 Correct 35 ms 10628 KB Output is correct
65 Correct 36 ms 10584 KB Output is correct
66 Correct 37 ms 10588 KB Output is correct
67 Correct 41 ms 10780 KB Output is correct
68 Correct 39 ms 10836 KB Output is correct
69 Correct 40 ms 10832 KB Output is correct
70 Correct 40 ms 10788 KB Output is correct
71 Correct 1 ms 6488 KB Output is correct
72 Correct 3 ms 6492 KB Output is correct
73 Correct 2 ms 6492 KB Output is correct
74 Correct 3 ms 6492 KB Output is correct
75 Correct 2 ms 6492 KB Output is correct
76 Correct 2 ms 6492 KB Output is correct
77 Correct 2 ms 6492 KB Output is correct
78 Correct 2 ms 6488 KB Output is correct
79 Correct 3 ms 6492 KB Output is correct
80 Correct 40 ms 10876 KB Output is correct
81 Correct 40 ms 10892 KB Output is correct
82 Correct 38 ms 10832 KB Output is correct
83 Correct 38 ms 10836 KB Output is correct
84 Correct 2 ms 6488 KB Output is correct
85 Correct 2 ms 6492 KB Output is correct
86 Correct 2 ms 6492 KB Output is correct
87 Correct 2 ms 6492 KB Output is correct
88 Correct 2 ms 6436 KB Output is correct
89 Correct 2 ms 6492 KB Output is correct
90 Correct 2 ms 6408 KB Output is correct
91 Correct 2 ms 6488 KB Output is correct
92 Correct 3 ms 6492 KB Output is correct
93 Correct 2 ms 6580 KB Output is correct
94 Correct 2 ms 6492 KB Output is correct
95 Correct 1 ms 6492 KB Output is correct
96 Correct 2 ms 6492 KB Output is correct
97 Correct 2 ms 6492 KB Output is correct
98 Correct 2 ms 6492 KB Output is correct
99 Correct 1 ms 6492 KB Output is correct
100 Correct 2 ms 6492 KB Output is correct
101 Correct 2 ms 6492 KB Output is correct
102 Correct 2 ms 6488 KB Output is correct
103 Correct 1 ms 6492 KB Output is correct
104 Correct 5 ms 7004 KB Output is correct
105 Correct 9 ms 8028 KB Output is correct
106 Correct 2 ms 6492 KB Output is correct
107 Correct 17 ms 9608 KB Output is correct
108 Correct 22 ms 11356 KB Output is correct
109 Correct 2 ms 6492 KB Output is correct
110 Correct 30 ms 11612 KB Output is correct
111 Correct 33 ms 12628 KB Output is correct
112 Correct 2 ms 6744 KB Output is correct
113 Correct 48 ms 17744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 8796 KB Output is correct
2 Correct 15 ms 8796 KB Output is correct
3 Correct 15 ms 8972 KB Output is correct
4 Correct 15 ms 8796 KB Output is correct
5 Correct 18 ms 8972 KB Output is correct
6 Correct 22 ms 9308 KB Output is correct
7 Correct 15 ms 9096 KB Output is correct
8 Correct 15 ms 8796 KB Output is correct
9 Correct 15 ms 8820 KB Output is correct
10 Correct 15 ms 9052 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 4 ms 6748 KB Output is correct
13 Correct 4 ms 6960 KB Output is correct
14 Correct 4 ms 6748 KB Output is correct
15 Correct 4 ms 6748 KB Output is correct
16 Correct 4 ms 6748 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 4 ms 6748 KB Output is correct
19 Correct 4 ms 6748 KB Output is correct
20 Incorrect 1 ms 6492 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6524 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6312 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6324 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 2 ms 6488 KB Output is correct
30 Correct 2 ms 6744 KB Output is correct
31 Correct 3 ms 6492 KB Output is correct
32 Correct 2 ms 6532 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6496 KB Output is correct
35 Correct 2 ms 6532 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 1 ms 6488 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6492 KB Output is correct
45 Correct 2 ms 6644 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 2 ms 6492 KB Output is correct
50 Correct 2 ms 6528 KB Output is correct
51 Correct 2 ms 6536 KB Output is correct
52 Incorrect 2 ms 6492 KB Output isn't correct
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 13652 KB Output is correct
2 Correct 33 ms 13396 KB Output is correct
3 Correct 22 ms 12636 KB Output is correct
4 Correct 6 ms 7516 KB Output is correct
5 Correct 5 ms 7004 KB Output is correct
6 Correct 9 ms 8028 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 17 ms 9560 KB Output is correct
9 Correct 22 ms 11364 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 30 ms 11604 KB Output is correct
12 Correct 34 ms 12636 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6524 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6312 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 2 ms 6324 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 32 ms 13860 KB Output is correct
40 Correct 31 ms 13404 KB Output is correct
41 Correct 22 ms 12636 KB Output is correct
42 Correct 6 ms 7512 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6536 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 38 ms 10960 KB Output is correct
58 Correct 41 ms 10856 KB Output is correct
59 Correct 39 ms 10844 KB Output is correct
60 Correct 39 ms 10844 KB Output is correct
61 Correct 40 ms 10780 KB Output is correct
62 Correct 39 ms 10844 KB Output is correct
63 Correct 36 ms 10576 KB Output is correct
64 Correct 35 ms 10628 KB Output is correct
65 Correct 36 ms 10584 KB Output is correct
66 Correct 37 ms 10588 KB Output is correct
67 Correct 41 ms 10780 KB Output is correct
68 Correct 39 ms 10836 KB Output is correct
69 Correct 40 ms 10832 KB Output is correct
70 Correct 40 ms 10788 KB Output is correct
71 Correct 1 ms 6488 KB Output is correct
72 Correct 3 ms 6492 KB Output is correct
73 Correct 2 ms 6492 KB Output is correct
74 Correct 3 ms 6492 KB Output is correct
75 Correct 2 ms 6492 KB Output is correct
76 Correct 2 ms 6492 KB Output is correct
77 Correct 2 ms 6492 KB Output is correct
78 Correct 2 ms 6488 KB Output is correct
79 Correct 3 ms 6492 KB Output is correct
80 Correct 40 ms 10876 KB Output is correct
81 Correct 40 ms 10892 KB Output is correct
82 Correct 38 ms 10832 KB Output is correct
83 Correct 38 ms 10836 KB Output is correct
84 Correct 2 ms 6488 KB Output is correct
85 Correct 2 ms 6492 KB Output is correct
86 Correct 2 ms 6492 KB Output is correct
87 Correct 2 ms 6492 KB Output is correct
88 Correct 2 ms 6436 KB Output is correct
89 Correct 2 ms 6492 KB Output is correct
90 Correct 2 ms 6408 KB Output is correct
91 Correct 2 ms 6488 KB Output is correct
92 Correct 3 ms 6492 KB Output is correct
93 Correct 2 ms 6580 KB Output is correct
94 Correct 2 ms 6492 KB Output is correct
95 Correct 1 ms 6492 KB Output is correct
96 Correct 2 ms 6492 KB Output is correct
97 Correct 2 ms 6492 KB Output is correct
98 Correct 2 ms 6492 KB Output is correct
99 Correct 1 ms 6492 KB Output is correct
100 Correct 2 ms 6492 KB Output is correct
101 Correct 2 ms 6492 KB Output is correct
102 Correct 2 ms 6488 KB Output is correct
103 Correct 1 ms 6492 KB Output is correct
104 Correct 5 ms 7004 KB Output is correct
105 Correct 9 ms 8028 KB Output is correct
106 Correct 2 ms 6492 KB Output is correct
107 Correct 17 ms 9608 KB Output is correct
108 Correct 22 ms 11356 KB Output is correct
109 Correct 2 ms 6492 KB Output is correct
110 Correct 30 ms 11612 KB Output is correct
111 Correct 33 ms 12628 KB Output is correct
112 Correct 2 ms 6744 KB Output is correct
113 Correct 48 ms 17744 KB Output is correct
114 Correct 15 ms 8796 KB Output is correct
115 Correct 15 ms 8796 KB Output is correct
116 Correct 15 ms 8972 KB Output is correct
117 Correct 15 ms 8796 KB Output is correct
118 Correct 18 ms 8972 KB Output is correct
119 Correct 22 ms 9308 KB Output is correct
120 Correct 15 ms 9096 KB Output is correct
121 Correct 15 ms 8796 KB Output is correct
122 Correct 15 ms 8820 KB Output is correct
123 Correct 15 ms 9052 KB Output is correct
124 Correct 1 ms 6492 KB Output is correct
125 Correct 4 ms 6748 KB Output is correct
126 Correct 4 ms 6960 KB Output is correct
127 Correct 4 ms 6748 KB Output is correct
128 Correct 4 ms 6748 KB Output is correct
129 Correct 4 ms 6748 KB Output is correct
130 Correct 3 ms 6748 KB Output is correct
131 Correct 4 ms 6748 KB Output is correct
132 Correct 4 ms 6748 KB Output is correct
133 Incorrect 1 ms 6492 KB Output isn't correct
134 Halted 0 ms 0 KB -