답안 #672630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672630 2022-12-17T04:19:56 Z Hanksburger 자매 도시 (APIO20_swap) C++17
100 / 100
151 ms 11228 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
int deg[100005], par[100005], sz[100005], w1[100005], w2[100005];
vector<pair<int, pair<int, int> > > edge;
int findPar(int x)
{
    return (par[x]==x)?x:findPar(par[x]);
}
void init(int n, int m, vector<int> u, vector<int> v, vector<int> w)
{
    for (int i=0; i<m; i++)
        edge.push_back({w[i], {u[i], v[i]}});
    sort(edge.begin(), edge.end());
    for (int i=0; i<n; i++)
    {
        par[i]=i;
        sz[i]=1;
        w1[i]=w2[i]=2e9;
    }
    for (int i=0; i<m; i++)
    {
        int x=edge[i].second.first, y=edge[i].second.second, z=edge[i].first;
        bool bridge=(deg[x]>=2 || deg[y]>=2);
        deg[x]++;
        deg[y]++;
        x=findPar(x);
        y=findPar(y);
        if (x==y)
        {
            w2[y]=min(w2[y], z);
            continue;
        }
        if (sz[x]>sz[y])
            swap(x, y);
        par[x]=y;
        sz[y]+=sz[x];
        w1[x]=z;
        if (bridge || w2[x]<2e9)
            w2[y]=min(w2[y], z);
    }
}
int getMinimumFuelCapacity(int x, int y)
{
    int ans=0;
    while (x!=y)
    {
        if (w1[x]<w1[y])
        {
            ans=w1[x];
            x=par[x];
        }
        else
        {
            ans=w1[y];
            y=par[y];
        }
    }
    while (par[x]!=x)
    {
        if (w2[x]<2e9)
            return max(ans, w2[x]);
        ans=w1[x];
        x=par[x];
    }
    if (w2[x]<2e9)
        return max(ans, w2[x]);
    return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 33 ms 4680 KB Output is correct
10 Correct 40 ms 5640 KB Output is correct
11 Correct 39 ms 5512 KB Output is correct
12 Correct 42 ms 5824 KB Output is correct
13 Correct 40 ms 5828 KB Output is correct
14 Correct 39 ms 4892 KB Output is correct
15 Correct 111 ms 7500 KB Output is correct
16 Correct 104 ms 7360 KB Output is correct
17 Correct 108 ms 7624 KB Output is correct
18 Correct 101 ms 7588 KB Output is correct
19 Correct 55 ms 4748 KB Output is correct
20 Correct 104 ms 8496 KB Output is correct
21 Correct 108 ms 8772 KB Output is correct
22 Correct 110 ms 9008 KB Output is correct
23 Correct 95 ms 9000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 88 ms 8496 KB Output is correct
4 Correct 93 ms 8544 KB Output is correct
5 Correct 91 ms 9008 KB Output is correct
6 Correct 84 ms 8500 KB Output is correct
7 Correct 93 ms 8940 KB Output is correct
8 Correct 86 ms 8492 KB Output is correct
9 Correct 86 ms 8620 KB Output is correct
10 Correct 86 ms 8476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 456 KB Output is correct
25 Correct 1 ms 452 KB Output is correct
26 Correct 1 ms 452 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 33 ms 4680 KB Output is correct
11 Correct 40 ms 5640 KB Output is correct
12 Correct 39 ms 5512 KB Output is correct
13 Correct 42 ms 5824 KB Output is correct
14 Correct 40 ms 5828 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 456 KB Output is correct
30 Correct 1 ms 452 KB Output is correct
31 Correct 1 ms 452 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 6 ms 1300 KB Output is correct
35 Correct 48 ms 5964 KB Output is correct
36 Correct 41 ms 5976 KB Output is correct
37 Correct 39 ms 5964 KB Output is correct
38 Correct 41 ms 5952 KB Output is correct
39 Correct 37 ms 5932 KB Output is correct
40 Correct 35 ms 5444 KB Output is correct
41 Correct 50 ms 5944 KB Output is correct
42 Correct 39 ms 5948 KB Output is correct
43 Correct 47 ms 6012 KB Output is correct
44 Correct 41 ms 5956 KB Output is correct
45 Correct 60 ms 7296 KB Output is correct
46 Correct 40 ms 5948 KB Output is correct
47 Correct 40 ms 5948 KB Output is correct
48 Correct 44 ms 6336 KB Output is correct
49 Correct 59 ms 7272 KB Output is correct
50 Correct 47 ms 4924 KB Output is correct
51 Correct 53 ms 6280 KB Output is correct
52 Correct 69 ms 8196 KB Output is correct
53 Correct 74 ms 8812 KB Output is correct
54 Correct 98 ms 9576 KB Output is correct
55 Correct 38 ms 5956 KB Output is correct
56 Correct 73 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 33 ms 4680 KB Output is correct
10 Correct 40 ms 5640 KB Output is correct
11 Correct 39 ms 5512 KB Output is correct
12 Correct 42 ms 5824 KB Output is correct
13 Correct 40 ms 5828 KB Output is correct
14 Correct 39 ms 4892 KB Output is correct
15 Correct 111 ms 7500 KB Output is correct
16 Correct 104 ms 7360 KB Output is correct
17 Correct 108 ms 7624 KB Output is correct
18 Correct 101 ms 7588 KB Output is correct
19 Correct 88 ms 8496 KB Output is correct
20 Correct 93 ms 8544 KB Output is correct
21 Correct 91 ms 9008 KB Output is correct
22 Correct 84 ms 8500 KB Output is correct
23 Correct 93 ms 8940 KB Output is correct
24 Correct 86 ms 8492 KB Output is correct
25 Correct 86 ms 8620 KB Output is correct
26 Correct 86 ms 8476 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 320 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 1 ms 324 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 6 ms 1300 KB Output is correct
37 Correct 48 ms 5964 KB Output is correct
38 Correct 41 ms 5976 KB Output is correct
39 Correct 39 ms 5964 KB Output is correct
40 Correct 41 ms 5952 KB Output is correct
41 Correct 37 ms 5932 KB Output is correct
42 Correct 35 ms 5444 KB Output is correct
43 Correct 50 ms 5944 KB Output is correct
44 Correct 39 ms 5948 KB Output is correct
45 Correct 47 ms 6012 KB Output is correct
46 Correct 41 ms 5956 KB Output is correct
47 Correct 12 ms 1556 KB Output is correct
48 Correct 112 ms 8588 KB Output is correct
49 Correct 108 ms 8620 KB Output is correct
50 Correct 105 ms 8608 KB Output is correct
51 Correct 106 ms 8480 KB Output is correct
52 Correct 101 ms 8256 KB Output is correct
53 Correct 94 ms 7732 KB Output is correct
54 Correct 108 ms 9120 KB Output is correct
55 Correct 107 ms 8608 KB Output is correct
56 Correct 113 ms 8632 KB Output is correct
57 Correct 107 ms 9124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 33 ms 4680 KB Output is correct
11 Correct 40 ms 5640 KB Output is correct
12 Correct 39 ms 5512 KB Output is correct
13 Correct 42 ms 5824 KB Output is correct
14 Correct 40 ms 5828 KB Output is correct
15 Correct 39 ms 4892 KB Output is correct
16 Correct 111 ms 7500 KB Output is correct
17 Correct 104 ms 7360 KB Output is correct
18 Correct 108 ms 7624 KB Output is correct
19 Correct 101 ms 7588 KB Output is correct
20 Correct 88 ms 8496 KB Output is correct
21 Correct 93 ms 8544 KB Output is correct
22 Correct 91 ms 9008 KB Output is correct
23 Correct 84 ms 8500 KB Output is correct
24 Correct 93 ms 8940 KB Output is correct
25 Correct 86 ms 8492 KB Output is correct
26 Correct 86 ms 8620 KB Output is correct
27 Correct 86 ms 8476 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 324 KB Output is correct
34 Correct 1 ms 324 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 6 ms 1300 KB Output is correct
38 Correct 48 ms 5964 KB Output is correct
39 Correct 41 ms 5976 KB Output is correct
40 Correct 39 ms 5964 KB Output is correct
41 Correct 41 ms 5952 KB Output is correct
42 Correct 37 ms 5932 KB Output is correct
43 Correct 35 ms 5444 KB Output is correct
44 Correct 50 ms 5944 KB Output is correct
45 Correct 39 ms 5948 KB Output is correct
46 Correct 47 ms 6012 KB Output is correct
47 Correct 41 ms 5956 KB Output is correct
48 Correct 12 ms 1556 KB Output is correct
49 Correct 112 ms 8588 KB Output is correct
50 Correct 108 ms 8620 KB Output is correct
51 Correct 105 ms 8608 KB Output is correct
52 Correct 106 ms 8480 KB Output is correct
53 Correct 101 ms 8256 KB Output is correct
54 Correct 94 ms 7732 KB Output is correct
55 Correct 108 ms 9120 KB Output is correct
56 Correct 107 ms 8608 KB Output is correct
57 Correct 113 ms 8632 KB Output is correct
58 Correct 107 ms 9124 KB Output is correct
59 Correct 55 ms 4748 KB Output is correct
60 Correct 104 ms 8496 KB Output is correct
61 Correct 108 ms 8772 KB Output is correct
62 Correct 110 ms 9008 KB Output is correct
63 Correct 95 ms 9000 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 328 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 456 KB Output is correct
70 Correct 1 ms 452 KB Output is correct
71 Correct 1 ms 452 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 468 KB Output is correct
74 Correct 60 ms 7296 KB Output is correct
75 Correct 40 ms 5948 KB Output is correct
76 Correct 40 ms 5948 KB Output is correct
77 Correct 44 ms 6336 KB Output is correct
78 Correct 59 ms 7272 KB Output is correct
79 Correct 47 ms 4924 KB Output is correct
80 Correct 53 ms 6280 KB Output is correct
81 Correct 69 ms 8196 KB Output is correct
82 Correct 74 ms 8812 KB Output is correct
83 Correct 98 ms 9576 KB Output is correct
84 Correct 38 ms 5956 KB Output is correct
85 Correct 73 ms 8540 KB Output is correct
86 Correct 38 ms 3348 KB Output is correct
87 Correct 132 ms 8524 KB Output is correct
88 Correct 103 ms 8512 KB Output is correct
89 Correct 100 ms 8544 KB Output is correct
90 Correct 130 ms 9160 KB Output is correct
91 Correct 113 ms 8604 KB Output is correct
92 Correct 108 ms 8992 KB Output is correct
93 Correct 143 ms 10356 KB Output is correct
94 Correct 134 ms 10792 KB Output is correct
95 Correct 151 ms 11228 KB Output is correct
96 Correct 93 ms 8492 KB Output is correct
97 Correct 116 ms 9792 KB Output is correct