답안 #1088348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088348 2024-09-14T09:30:35 Z modwwe 자매 도시 (APIO20_swap) C++17
100 / 100
116 ms 15188 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int inf = 2e9;
const int maxn = 2e5+5;
int a[maxn],c[maxn],d[maxn],p[maxn];

int findpar(int u){
    return (p[u]<0?u:findpar(p[u]));
}
void unions(int u,int v,int w,bool e){
    u=findpar(u);v=findpar(v);
    if(u==v) c[u]=min(c[u],w);
    else{
        if(p[u]>p[v]) swap(u,v);
        p[u]+=p[v];p[v]=u;a[v]=w;
        c[u]=min(c[u],max(w,e?0:c[v]));
    }
}

void init(int N, int M,
          std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    for(int i=0;i<N;i++) p[i]=-1,a[i]=c[i]=inf;
    vector<int> ord(M);
    iota(ord.begin(),ord.end(),0);
    sort(ord.begin(),ord.end(),[&](int x,int y){
        return W[x]<W[y];
    });
    for(int i:ord){
        d[U[i]]++;d[V[i]]++;
        unions(U[i],V[i],W[i],(d[U[i]]>=3 || d[V[i]]>=3));
    }
}

int getMinimumFuelCapacity(int u, int v) {
    int w=-1;
    while(u!=v){
        if(a[u]<a[v]) w=a[u],u=p[u];
        else w=a[v],v=p[v];
    }
    while(u>=0){
        if(c[u]!=inf) return max(w,c[u]);
        w=a[u];u=p[u];
    }
    return -1;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 24 ms 5312 KB Output is correct
10 Correct 31 ms 6484 KB Output is correct
11 Correct 30 ms 6484 KB Output is correct
12 Correct 33 ms 6736 KB Output is correct
13 Correct 30 ms 6748 KB Output is correct
14 Correct 30 ms 5716 KB Output is correct
15 Correct 82 ms 10332 KB Output is correct
16 Correct 86 ms 10236 KB Output is correct
17 Correct 88 ms 10576 KB Output is correct
18 Correct 69 ms 10576 KB Output is correct
19 Correct 44 ms 6248 KB Output is correct
20 Correct 91 ms 11348 KB Output is correct
21 Correct 83 ms 11424 KB Output is correct
22 Correct 85 ms 11820 KB Output is correct
23 Correct 73 ms 11824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 72 ms 11140 KB Output is correct
4 Correct 66 ms 10804 KB Output is correct
5 Correct 67 ms 11232 KB Output is correct
6 Correct 62 ms 10920 KB Output is correct
7 Correct 63 ms 11188 KB Output is correct
8 Correct 59 ms 10900 KB Output is correct
9 Correct 63 ms 11092 KB Output is correct
10 Correct 65 ms 10912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 496 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 24 ms 5312 KB Output is correct
11 Correct 31 ms 6484 KB Output is correct
12 Correct 30 ms 6484 KB Output is correct
13 Correct 33 ms 6736 KB Output is correct
14 Correct 30 ms 6748 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 496 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 4 ms 1116 KB Output is correct
35 Correct 29 ms 6476 KB Output is correct
36 Correct 30 ms 6480 KB Output is correct
37 Correct 29 ms 6468 KB Output is correct
38 Correct 30 ms 6480 KB Output is correct
39 Correct 28 ms 6228 KB Output is correct
40 Correct 28 ms 5980 KB Output is correct
41 Correct 30 ms 6740 KB Output is correct
42 Correct 29 ms 6344 KB Output is correct
43 Correct 28 ms 6488 KB Output is correct
44 Correct 31 ms 6744 KB Output is correct
45 Correct 57 ms 8788 KB Output is correct
46 Correct 29 ms 6484 KB Output is correct
47 Correct 28 ms 6484 KB Output is correct
48 Correct 32 ms 6992 KB Output is correct
49 Correct 47 ms 7412 KB Output is correct
50 Correct 35 ms 5968 KB Output is correct
51 Correct 42 ms 7504 KB Output is correct
52 Correct 51 ms 9744 KB Output is correct
53 Correct 52 ms 10572 KB Output is correct
54 Correct 73 ms 11364 KB Output is correct
55 Correct 29 ms 6480 KB Output is correct
56 Correct 55 ms 10324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 24 ms 5312 KB Output is correct
10 Correct 31 ms 6484 KB Output is correct
11 Correct 30 ms 6484 KB Output is correct
12 Correct 33 ms 6736 KB Output is correct
13 Correct 30 ms 6748 KB Output is correct
14 Correct 30 ms 5716 KB Output is correct
15 Correct 82 ms 10332 KB Output is correct
16 Correct 86 ms 10236 KB Output is correct
17 Correct 88 ms 10576 KB Output is correct
18 Correct 69 ms 10576 KB Output is correct
19 Correct 72 ms 11140 KB Output is correct
20 Correct 66 ms 10804 KB Output is correct
21 Correct 67 ms 11232 KB Output is correct
22 Correct 62 ms 10920 KB Output is correct
23 Correct 63 ms 11188 KB Output is correct
24 Correct 59 ms 10900 KB Output is correct
25 Correct 63 ms 11092 KB Output is correct
26 Correct 65 ms 10912 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 4 ms 1116 KB Output is correct
37 Correct 29 ms 6476 KB Output is correct
38 Correct 30 ms 6480 KB Output is correct
39 Correct 29 ms 6468 KB Output is correct
40 Correct 30 ms 6480 KB Output is correct
41 Correct 28 ms 6228 KB Output is correct
42 Correct 28 ms 5980 KB Output is correct
43 Correct 30 ms 6740 KB Output is correct
44 Correct 29 ms 6344 KB Output is correct
45 Correct 28 ms 6488 KB Output is correct
46 Correct 31 ms 6744 KB Output is correct
47 Correct 8 ms 1560 KB Output is correct
48 Correct 85 ms 10956 KB Output is correct
49 Correct 83 ms 11060 KB Output is correct
50 Correct 81 ms 11056 KB Output is correct
51 Correct 80 ms 10816 KB Output is correct
52 Correct 87 ms 10640 KB Output is correct
53 Correct 70 ms 10268 KB Output is correct
54 Correct 89 ms 11824 KB Output is correct
55 Correct 82 ms 11056 KB Output is correct
56 Correct 93 ms 10928 KB Output is correct
57 Correct 89 ms 11824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 24 ms 5312 KB Output is correct
11 Correct 31 ms 6484 KB Output is correct
12 Correct 30 ms 6484 KB Output is correct
13 Correct 33 ms 6736 KB Output is correct
14 Correct 30 ms 6748 KB Output is correct
15 Correct 30 ms 5716 KB Output is correct
16 Correct 82 ms 10332 KB Output is correct
17 Correct 86 ms 10236 KB Output is correct
18 Correct 88 ms 10576 KB Output is correct
19 Correct 69 ms 10576 KB Output is correct
20 Correct 72 ms 11140 KB Output is correct
21 Correct 66 ms 10804 KB Output is correct
22 Correct 67 ms 11232 KB Output is correct
23 Correct 62 ms 10920 KB Output is correct
24 Correct 63 ms 11188 KB Output is correct
25 Correct 59 ms 10900 KB Output is correct
26 Correct 63 ms 11092 KB Output is correct
27 Correct 65 ms 10912 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 4 ms 1116 KB Output is correct
38 Correct 29 ms 6476 KB Output is correct
39 Correct 30 ms 6480 KB Output is correct
40 Correct 29 ms 6468 KB Output is correct
41 Correct 30 ms 6480 KB Output is correct
42 Correct 28 ms 6228 KB Output is correct
43 Correct 28 ms 5980 KB Output is correct
44 Correct 30 ms 6740 KB Output is correct
45 Correct 29 ms 6344 KB Output is correct
46 Correct 28 ms 6488 KB Output is correct
47 Correct 31 ms 6744 KB Output is correct
48 Correct 8 ms 1560 KB Output is correct
49 Correct 85 ms 10956 KB Output is correct
50 Correct 83 ms 11060 KB Output is correct
51 Correct 81 ms 11056 KB Output is correct
52 Correct 80 ms 10816 KB Output is correct
53 Correct 87 ms 10640 KB Output is correct
54 Correct 70 ms 10268 KB Output is correct
55 Correct 89 ms 11824 KB Output is correct
56 Correct 82 ms 11056 KB Output is correct
57 Correct 93 ms 10928 KB Output is correct
58 Correct 89 ms 11824 KB Output is correct
59 Correct 44 ms 6248 KB Output is correct
60 Correct 91 ms 11348 KB Output is correct
61 Correct 83 ms 11424 KB Output is correct
62 Correct 85 ms 11820 KB Output is correct
63 Correct 73 ms 11824 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 1 ms 496 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 460 KB Output is correct
73 Correct 1 ms 460 KB Output is correct
74 Correct 57 ms 8788 KB Output is correct
75 Correct 29 ms 6484 KB Output is correct
76 Correct 28 ms 6484 KB Output is correct
77 Correct 32 ms 6992 KB Output is correct
78 Correct 47 ms 7412 KB Output is correct
79 Correct 35 ms 5968 KB Output is correct
80 Correct 42 ms 7504 KB Output is correct
81 Correct 51 ms 9744 KB Output is correct
82 Correct 52 ms 10572 KB Output is correct
83 Correct 73 ms 11364 KB Output is correct
84 Correct 29 ms 6480 KB Output is correct
85 Correct 55 ms 10324 KB Output is correct
86 Correct 26 ms 4184 KB Output is correct
87 Correct 81 ms 10920 KB Output is correct
88 Correct 80 ms 11048 KB Output is correct
89 Correct 113 ms 10960 KB Output is correct
90 Correct 90 ms 11348 KB Output is correct
91 Correct 88 ms 11316 KB Output is correct
92 Correct 86 ms 11980 KB Output is correct
93 Correct 100 ms 13732 KB Output is correct
94 Correct 105 ms 14456 KB Output is correct
95 Correct 116 ms 15188 KB Output is correct
96 Correct 72 ms 11056 KB Output is correct
97 Correct 85 ms 13128 KB Output is correct