답안 #308139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308139 2020-09-30T05:08:14 Z tjdgus4384 자매 도시 (APIO20_swap) C++14
100 / 100
525 ms 32228 KB
#include<bits/stdc++.h>
using namespace std;
vector<int> group[100010];
vector<pair<int, int> > pa[100010];
vector<pair<int, pair<int, int> > > mv;
int p[100010], cycle[100010], outd[100010], sizep[100010], cnt[100010];

int find(int x){
    if(p[x] == x) return x;
    return find(p[x]);
}

void init(int n, int m, vector<int> u, vector<int> v, vector<int> w){
    for(int i = 0;i < n;i++){
        sizep[i] = 1; p[i] = i;
        group[i].push_back(i);
        pa[i].push_back({0, i});
    }
    for(int i = 0;i < m;i++){
        mv.push_back({w[i], {u[i], v[i]}});
    }
    sort(mv.begin(), mv.end());
    for(int i = 0;i < m;i++){
        int u1 = find(mv[i].second.first);
        int u2 = find(mv[i].second.second);
        cnt[mv[i].second.first]++; cnt[mv[i].second.second]++;
        if(u1 == u2){
            if(cycle[u1] == 0) cycle[u1] = mv[i].first;
            if(cnt[mv[i].second.first] >= 3 || cnt[mv[i].second.second] >= 3){
                if(outd[u1] == 0) outd[u1] = mv[i].first;
            }
        }
        else{
            if(sizep[u1] < sizep[u2]) swap(u1, u2);
            for(int j = 0;j < group[u2].size();j++){
                pa[group[u2][j]].push_back({mv[i].first, u1});
                group[u1].push_back(group[u2][j]);
                p[group[u2][j]] = u1;
            }
            sizep[u1] += sizep[u2];
            if(cycle[u1] || cycle[u2]){
                if(cycle[u2] == 0) cycle[u2] = mv[i].first;
                if(cycle[u1] == 0) cycle[u1] = mv[i].first;
            }
            if(outd[u1] || outd[u2] || cnt[mv[i].second.first] >= 3 || cnt[mv[i].second.second] >= 3){
                if(outd[u1] == 0) outd[u1] = mv[i].first;
                if(outd[u2] == 0) outd[u2] = mv[i].first;
            }
        }
    }
}

int getMinimumFuelCapacity(int X, int Y){
    int x = X, y = Y, ans = 1000000001;
    int s1 = 0, e1 = pa[x].size() - 1;
    while(s1 < e1){
        int mid = (s1+e1)/2;
        if(cycle[pa[x][mid].second]||outd[pa[x][mid].second]) e1 = mid;
        else s1 = mid+1;
    }
    int s2 = 0, e2 = pa[y].size() - 1;
    while(s2 < e2){
        int mid = (s2+e2)/2;
        if(cycle[pa[y][mid].second]||outd[pa[y][mid].second]) e2 = mid;
        else s2 = mid+1;
    }
    if(cycle[pa[x][s1].second]) ans = min(ans, cycle[pa[x][s1].second]);
    if(outd[pa[y][s2].second]) ans = min(ans, outd[pa[y][s2].second]);
    if(outd[pa[x][s1].second]) ans = min(ans, outd[pa[x][s1].second]);
    if(cycle[pa[y][s2].second]) ans = min(ans, cycle[pa[y][s2].second]);
    if(ans == 1000000001) return -1;
    int s = 0, e = 1000000001;
    while(s < e){
        //printf("%d %d\n", s, e);
        int mid = (s+e)/2;
        s1 = 0, e1 = pa[x].size() - 1;
        while(s1 < e1){
            int mid1 = (s1+e1+1)/2;
            if(pa[x][mid1].first > mid) e1 = mid1-1;
            else s1 = mid1;
        }
        s2 = 0, e2 = pa[y].size() - 1;
        while(s2 < e2){
            int mid2 = (s2+e2+1)/2;
            if(pa[y][mid2].first > mid) e2 = mid2-1;
            else s2 = mid2;
        }
        if(pa[x][s1].second != pa[y][s2].second) s = mid+1;
        else e = mid;
    }
    return max(ans, s);
}

Compilation message

swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:35:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             for(int j = 0;j < group[u2].size();j++){
      |                           ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 5120 KB Output is correct
5 Correct 4 ms 5248 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5248 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 178 ms 22124 KB Output is correct
10 Correct 232 ms 25452 KB Output is correct
11 Correct 232 ms 25068 KB Output is correct
12 Correct 249 ms 26220 KB Output is correct
13 Correct 135 ms 18924 KB Output is correct
14 Correct 192 ms 21996 KB Output is correct
15 Correct 358 ms 27636 KB Output is correct
16 Correct 334 ms 26980 KB Output is correct
17 Correct 359 ms 28372 KB Output is correct
18 Correct 238 ms 20948 KB Output is correct
19 Correct 194 ms 11704 KB Output is correct
20 Correct 482 ms 28800 KB Output is correct
21 Correct 482 ms 28328 KB Output is correct
22 Correct 511 ms 29752 KB Output is correct
23 Correct 320 ms 22228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 288 ms 19724 KB Output is correct
4 Correct 287 ms 20180 KB Output is correct
5 Correct 299 ms 20096 KB Output is correct
6 Correct 286 ms 20308 KB Output is correct
7 Correct 299 ms 20076 KB Output is correct
8 Correct 280 ms 19872 KB Output is correct
9 Correct 293 ms 19944 KB Output is correct
10 Correct 285 ms 19748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5248 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5248 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 4 ms 5248 KB Output is correct
12 Correct 5 ms 5248 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 4 ms 5248 KB Output is correct
16 Correct 4 ms 5248 KB Output is correct
17 Correct 5 ms 5248 KB Output is correct
18 Correct 4 ms 5248 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 4 ms 5248 KB Output is correct
21 Correct 4 ms 5120 KB Output is correct
22 Correct 5 ms 5120 KB Output is correct
23 Correct 4 ms 5120 KB Output is correct
24 Correct 5 ms 5248 KB Output is correct
25 Correct 5 ms 5248 KB Output is correct
26 Correct 5 ms 5248 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 5 ms 5248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5248 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5248 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 178 ms 22124 KB Output is correct
11 Correct 232 ms 25452 KB Output is correct
12 Correct 232 ms 25068 KB Output is correct
13 Correct 249 ms 26220 KB Output is correct
14 Correct 135 ms 18924 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 4 ms 5248 KB Output is correct
17 Correct 5 ms 5248 KB Output is correct
18 Correct 4 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 4 ms 5248 KB Output is correct
21 Correct 4 ms 5248 KB Output is correct
22 Correct 5 ms 5248 KB Output is correct
23 Correct 4 ms 5248 KB Output is correct
24 Correct 20 ms 7616 KB Output is correct
25 Correct 233 ms 26336 KB Output is correct
26 Correct 232 ms 26348 KB Output is correct
27 Correct 233 ms 25836 KB Output is correct
28 Correct 228 ms 24940 KB Output is correct
29 Correct 224 ms 24684 KB Output is correct
30 Correct 191 ms 22636 KB Output is correct
31 Correct 249 ms 26732 KB Output is correct
32 Correct 239 ms 26732 KB Output is correct
33 Correct 132 ms 18668 KB Output is correct
34 Correct 219 ms 24624 KB Output is correct
35 Correct 4 ms 5120 KB Output is correct
36 Correct 4 ms 5248 KB Output is correct
37 Correct 4 ms 5120 KB Output is correct
38 Correct 5 ms 5120 KB Output is correct
39 Correct 4 ms 5120 KB Output is correct
40 Correct 5 ms 5248 KB Output is correct
41 Correct 5 ms 5248 KB Output is correct
42 Correct 5 ms 5248 KB Output is correct
43 Correct 6 ms 5120 KB Output is correct
44 Correct 5 ms 5248 KB Output is correct
45 Correct 171 ms 19552 KB Output is correct
46 Correct 232 ms 26220 KB Output is correct
47 Correct 200 ms 23364 KB Output is correct
48 Correct 167 ms 20332 KB Output is correct
49 Correct 88 ms 12012 KB Output is correct
50 Correct 74 ms 10220 KB Output is correct
51 Correct 134 ms 17132 KB Output is correct
52 Correct 268 ms 27752 KB Output is correct
53 Correct 233 ms 24168 KB Output is correct
54 Correct 295 ms 30312 KB Output is correct
55 Correct 135 ms 19184 KB Output is correct
56 Correct 218 ms 22892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 5120 KB Output is correct
5 Correct 4 ms 5248 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5248 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 178 ms 22124 KB Output is correct
10 Correct 232 ms 25452 KB Output is correct
11 Correct 232 ms 25068 KB Output is correct
12 Correct 249 ms 26220 KB Output is correct
13 Correct 135 ms 18924 KB Output is correct
14 Correct 192 ms 21996 KB Output is correct
15 Correct 358 ms 27636 KB Output is correct
16 Correct 334 ms 26980 KB Output is correct
17 Correct 359 ms 28372 KB Output is correct
18 Correct 238 ms 20948 KB Output is correct
19 Correct 288 ms 19724 KB Output is correct
20 Correct 287 ms 20180 KB Output is correct
21 Correct 299 ms 20096 KB Output is correct
22 Correct 286 ms 20308 KB Output is correct
23 Correct 299 ms 20076 KB Output is correct
24 Correct 280 ms 19872 KB Output is correct
25 Correct 293 ms 19944 KB Output is correct
26 Correct 285 ms 19748 KB Output is correct
27 Correct 4 ms 5120 KB Output is correct
28 Correct 4 ms 5248 KB Output is correct
29 Correct 5 ms 5248 KB Output is correct
30 Correct 4 ms 5120 KB Output is correct
31 Correct 4 ms 5120 KB Output is correct
32 Correct 4 ms 5248 KB Output is correct
33 Correct 4 ms 5248 KB Output is correct
34 Correct 5 ms 5248 KB Output is correct
35 Correct 4 ms 5248 KB Output is correct
36 Correct 20 ms 7616 KB Output is correct
37 Correct 233 ms 26336 KB Output is correct
38 Correct 232 ms 26348 KB Output is correct
39 Correct 233 ms 25836 KB Output is correct
40 Correct 228 ms 24940 KB Output is correct
41 Correct 224 ms 24684 KB Output is correct
42 Correct 191 ms 22636 KB Output is correct
43 Correct 249 ms 26732 KB Output is correct
44 Correct 239 ms 26732 KB Output is correct
45 Correct 132 ms 18668 KB Output is correct
46 Correct 219 ms 24624 KB Output is correct
47 Correct 39 ms 7732 KB Output is correct
48 Correct 458 ms 29060 KB Output is correct
49 Correct 451 ms 28756 KB Output is correct
50 Correct 453 ms 28760 KB Output is correct
51 Correct 442 ms 28128 KB Output is correct
52 Correct 417 ms 26392 KB Output is correct
53 Correct 365 ms 21600 KB Output is correct
54 Correct 477 ms 29524 KB Output is correct
55 Correct 459 ms 29524 KB Output is correct
56 Correct 322 ms 21844 KB Output is correct
57 Correct 456 ms 27220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5248 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5248 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 178 ms 22124 KB Output is correct
11 Correct 232 ms 25452 KB Output is correct
12 Correct 232 ms 25068 KB Output is correct
13 Correct 249 ms 26220 KB Output is correct
14 Correct 135 ms 18924 KB Output is correct
15 Correct 192 ms 21996 KB Output is correct
16 Correct 358 ms 27636 KB Output is correct
17 Correct 334 ms 26980 KB Output is correct
18 Correct 359 ms 28372 KB Output is correct
19 Correct 238 ms 20948 KB Output is correct
20 Correct 288 ms 19724 KB Output is correct
21 Correct 287 ms 20180 KB Output is correct
22 Correct 299 ms 20096 KB Output is correct
23 Correct 286 ms 20308 KB Output is correct
24 Correct 299 ms 20076 KB Output is correct
25 Correct 280 ms 19872 KB Output is correct
26 Correct 293 ms 19944 KB Output is correct
27 Correct 285 ms 19748 KB Output is correct
28 Correct 4 ms 5120 KB Output is correct
29 Correct 4 ms 5248 KB Output is correct
30 Correct 5 ms 5248 KB Output is correct
31 Correct 4 ms 5120 KB Output is correct
32 Correct 4 ms 5120 KB Output is correct
33 Correct 4 ms 5248 KB Output is correct
34 Correct 4 ms 5248 KB Output is correct
35 Correct 5 ms 5248 KB Output is correct
36 Correct 4 ms 5248 KB Output is correct
37 Correct 20 ms 7616 KB Output is correct
38 Correct 233 ms 26336 KB Output is correct
39 Correct 232 ms 26348 KB Output is correct
40 Correct 233 ms 25836 KB Output is correct
41 Correct 228 ms 24940 KB Output is correct
42 Correct 224 ms 24684 KB Output is correct
43 Correct 191 ms 22636 KB Output is correct
44 Correct 249 ms 26732 KB Output is correct
45 Correct 239 ms 26732 KB Output is correct
46 Correct 132 ms 18668 KB Output is correct
47 Correct 219 ms 24624 KB Output is correct
48 Correct 39 ms 7732 KB Output is correct
49 Correct 458 ms 29060 KB Output is correct
50 Correct 451 ms 28756 KB Output is correct
51 Correct 453 ms 28760 KB Output is correct
52 Correct 442 ms 28128 KB Output is correct
53 Correct 417 ms 26392 KB Output is correct
54 Correct 365 ms 21600 KB Output is correct
55 Correct 477 ms 29524 KB Output is correct
56 Correct 459 ms 29524 KB Output is correct
57 Correct 322 ms 21844 KB Output is correct
58 Correct 456 ms 27220 KB Output is correct
59 Correct 194 ms 11704 KB Output is correct
60 Correct 482 ms 28800 KB Output is correct
61 Correct 482 ms 28328 KB Output is correct
62 Correct 511 ms 29752 KB Output is correct
63 Correct 320 ms 22228 KB Output is correct
64 Correct 4 ms 5120 KB Output is correct
65 Correct 4 ms 5248 KB Output is correct
66 Correct 4 ms 5120 KB Output is correct
67 Correct 5 ms 5120 KB Output is correct
68 Correct 4 ms 5120 KB Output is correct
69 Correct 5 ms 5248 KB Output is correct
70 Correct 5 ms 5248 KB Output is correct
71 Correct 5 ms 5248 KB Output is correct
72 Correct 6 ms 5120 KB Output is correct
73 Correct 5 ms 5248 KB Output is correct
74 Correct 171 ms 19552 KB Output is correct
75 Correct 232 ms 26220 KB Output is correct
76 Correct 200 ms 23364 KB Output is correct
77 Correct 167 ms 20332 KB Output is correct
78 Correct 88 ms 12012 KB Output is correct
79 Correct 74 ms 10220 KB Output is correct
80 Correct 134 ms 17132 KB Output is correct
81 Correct 268 ms 27752 KB Output is correct
82 Correct 233 ms 24168 KB Output is correct
83 Correct 295 ms 30312 KB Output is correct
84 Correct 135 ms 19184 KB Output is correct
85 Correct 218 ms 22892 KB Output is correct
86 Correct 103 ms 11044 KB Output is correct
87 Correct 452 ms 28388 KB Output is correct
88 Correct 458 ms 28632 KB Output is correct
89 Correct 351 ms 22028 KB Output is correct
90 Correct 256 ms 13968 KB Output is correct
91 Correct 269 ms 14096 KB Output is correct
92 Correct 335 ms 19784 KB Output is correct
93 Correct 488 ms 29728 KB Output is correct
94 Correct 464 ms 26820 KB Output is correct
95 Correct 525 ms 32228 KB Output is correct
96 Correct 316 ms 22100 KB Output is correct
97 Correct 428 ms 24616 KB Output is correct