Submission #348583

# Submission time Handle Problem Language Result Execution time Memory
348583 2021-01-15T08:59:09 Z denkendoemeer Swapping Cities (APIO20_swap) C++14
100 / 100
370 ms 38152 KB
#include<bits/stdc++.h>
#include "swap.h"
#define ll long long
const int inf=1e9;
using namespace std;
vector<pair<int,pair<int,int>>>ed;
vector<pair<int,int>>dsu[100005];
int ans[100005],t[100005];
vector<int>g[100005];
void init(int n,int m,vector<int>x,vector<int>y,vector<int>w)
{
    int i;
    for(i=0;i<n;i++)
        ans[i]=inf;
    for(i=0;i<n;i++){
        dsu[i].push_back({0,i});
        g[i].push_back(i);
    }
    for(i=0;i<m;i++)
        ed.push_back({w[i],{y[i],x[i]}});
    sort(ed.begin(),ed.end());
    for(auto &it:ed){
        int y,x,w;
        y=it.second.first;
        x=it.second.second;
        w=it.first;
        int ty=dsu[y].back().second,tx=dsu[x].back().second;
        if (ty==tx){
            ans[ty]=min(ans[ty],w);
            continue;
        }
        ++t[y];
        ++t[x];
        if (g[ty].size()>g[tx].size())
            swap(tx,ty),swap(x,y);
        ans[tx]=min(ans[tx],max(w,ans[ty]));
        if (t[x]>=3 || t[y]>=3)
            ans[tx]=min(ans[tx],w);
        for(auto it2:g[ty]){
            g[tx].push_back(it2);
            dsu[it2].push_back({w,tx});
        }
    }
}
int getMinimumFuelCapacity(int x,int y)
{
    int tx=dsu[x].size()-1,ty=dsu[y].size()-1;
    int rez=inf,mini=inf;
    while(tx>=0 && ty>=0 && dsu[x][tx].second==dsu[y][ty].second){
        rez=max(dsu[x][tx].first,dsu[y][ty].first);
        mini=min(mini,max(rez,ans[dsu[x][tx].second]));
        tx--;
        ty--;
    }
    rez=max(rez,mini);
    if (rez==inf)
        return -1;
    return rez;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5004 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 5 ms 5100 KB Output is correct
5 Correct 5 ms 5228 KB Output is correct
6 Correct 5 ms 5228 KB Output is correct
7 Correct 5 ms 5228 KB Output is correct
8 Correct 5 ms 5228 KB Output is correct
9 Correct 180 ms 23636 KB Output is correct
10 Correct 224 ms 27236 KB Output is correct
11 Correct 227 ms 26848 KB Output is correct
12 Correct 226 ms 28108 KB Output is correct
13 Correct 122 ms 20704 KB Output is correct
14 Correct 165 ms 23652 KB Output is correct
15 Correct 295 ms 31852 KB Output is correct
16 Correct 283 ms 31120 KB Output is correct
17 Correct 326 ms 32712 KB Output is correct
18 Correct 201 ms 24776 KB Output is correct
19 Correct 79 ms 13612 KB Output is correct
20 Correct 289 ms 32868 KB Output is correct
21 Correct 298 ms 32476 KB Output is correct
22 Correct 304 ms 33864 KB Output is correct
23 Correct 206 ms 26184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5004 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 170 ms 22788 KB Output is correct
4 Correct 189 ms 23128 KB Output is correct
5 Correct 179 ms 23416 KB Output is correct
6 Correct 175 ms 23112 KB Output is correct
7 Correct 175 ms 23264 KB Output is correct
8 Correct 168 ms 22800 KB Output is correct
9 Correct 182 ms 23136 KB Output is correct
10 Correct 173 ms 22696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 5004 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 4 ms 4972 KB Output is correct
5 Correct 5 ms 5100 KB Output is correct
6 Correct 5 ms 5228 KB Output is correct
7 Correct 5 ms 5228 KB Output is correct
8 Correct 5 ms 5228 KB Output is correct
9 Correct 5 ms 5228 KB Output is correct
10 Correct 5 ms 5228 KB Output is correct
11 Correct 5 ms 5228 KB Output is correct
12 Correct 5 ms 5228 KB Output is correct
13 Correct 4 ms 5228 KB Output is correct
14 Correct 5 ms 5228 KB Output is correct
15 Correct 6 ms 5228 KB Output is correct
16 Correct 5 ms 5228 KB Output is correct
17 Correct 5 ms 5228 KB Output is correct
18 Correct 5 ms 5228 KB Output is correct
19 Correct 5 ms 5100 KB Output is correct
20 Correct 5 ms 5228 KB Output is correct
21 Correct 5 ms 5228 KB Output is correct
22 Correct 5 ms 5100 KB Output is correct
23 Correct 4 ms 5100 KB Output is correct
24 Correct 5 ms 5228 KB Output is correct
25 Correct 5 ms 5228 KB Output is correct
26 Correct 5 ms 5228 KB Output is correct
27 Correct 4 ms 5100 KB Output is correct
28 Correct 5 ms 5228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 5004 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 4 ms 4972 KB Output is correct
5 Correct 5 ms 5100 KB Output is correct
6 Correct 5 ms 5228 KB Output is correct
7 Correct 5 ms 5228 KB Output is correct
8 Correct 5 ms 5228 KB Output is correct
9 Correct 5 ms 5228 KB Output is correct
10 Correct 180 ms 23636 KB Output is correct
11 Correct 224 ms 27236 KB Output is correct
12 Correct 227 ms 26848 KB Output is correct
13 Correct 226 ms 28108 KB Output is correct
14 Correct 122 ms 20704 KB Output is correct
15 Correct 5 ms 5228 KB Output is correct
16 Correct 5 ms 5228 KB Output is correct
17 Correct 5 ms 5228 KB Output is correct
18 Correct 4 ms 5228 KB Output is correct
19 Correct 5 ms 5228 KB Output is correct
20 Correct 6 ms 5228 KB Output is correct
21 Correct 5 ms 5228 KB Output is correct
22 Correct 5 ms 5228 KB Output is correct
23 Correct 5 ms 5228 KB Output is correct
24 Correct 17 ms 7728 KB Output is correct
25 Correct 218 ms 27876 KB Output is correct
26 Correct 206 ms 27616 KB Output is correct
27 Correct 207 ms 27108 KB Output is correct
28 Correct 202 ms 26228 KB Output is correct
29 Correct 184 ms 25824 KB Output is correct
30 Correct 170 ms 23800 KB Output is correct
31 Correct 226 ms 28512 KB Output is correct
32 Correct 234 ms 28384 KB Output is correct
33 Correct 112 ms 19680 KB Output is correct
34 Correct 186 ms 25860 KB Output is correct
35 Correct 5 ms 5100 KB Output is correct
36 Correct 5 ms 5228 KB Output is correct
37 Correct 5 ms 5228 KB Output is correct
38 Correct 5 ms 5100 KB Output is correct
39 Correct 4 ms 5100 KB Output is correct
40 Correct 5 ms 5228 KB Output is correct
41 Correct 5 ms 5228 KB Output is correct
42 Correct 5 ms 5228 KB Output is correct
43 Correct 4 ms 5100 KB Output is correct
44 Correct 5 ms 5228 KB Output is correct
45 Correct 150 ms 21984 KB Output is correct
46 Correct 206 ms 27452 KB Output is correct
47 Correct 177 ms 24036 KB Output is correct
48 Correct 144 ms 21472 KB Output is correct
49 Correct 77 ms 14820 KB Output is correct
50 Correct 62 ms 12392 KB Output is correct
51 Correct 120 ms 19040 KB Output is correct
52 Correct 241 ms 30428 KB Output is correct
53 Correct 218 ms 26844 KB Output is correct
54 Correct 271 ms 33752 KB Output is correct
55 Correct 114 ms 19936 KB Output is correct
56 Correct 187 ms 25564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5004 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 5 ms 5100 KB Output is correct
5 Correct 5 ms 5228 KB Output is correct
6 Correct 5 ms 5228 KB Output is correct
7 Correct 5 ms 5228 KB Output is correct
8 Correct 5 ms 5228 KB Output is correct
9 Correct 180 ms 23636 KB Output is correct
10 Correct 224 ms 27236 KB Output is correct
11 Correct 227 ms 26848 KB Output is correct
12 Correct 226 ms 28108 KB Output is correct
13 Correct 122 ms 20704 KB Output is correct
14 Correct 165 ms 23652 KB Output is correct
15 Correct 295 ms 31852 KB Output is correct
16 Correct 283 ms 31120 KB Output is correct
17 Correct 326 ms 32712 KB Output is correct
18 Correct 201 ms 24776 KB Output is correct
19 Correct 170 ms 22788 KB Output is correct
20 Correct 189 ms 23128 KB Output is correct
21 Correct 179 ms 23416 KB Output is correct
22 Correct 175 ms 23112 KB Output is correct
23 Correct 175 ms 23264 KB Output is correct
24 Correct 168 ms 22800 KB Output is correct
25 Correct 182 ms 23136 KB Output is correct
26 Correct 173 ms 22696 KB Output is correct
27 Correct 5 ms 5228 KB Output is correct
28 Correct 5 ms 5228 KB Output is correct
29 Correct 5 ms 5228 KB Output is correct
30 Correct 4 ms 5228 KB Output is correct
31 Correct 5 ms 5228 KB Output is correct
32 Correct 6 ms 5228 KB Output is correct
33 Correct 5 ms 5228 KB Output is correct
34 Correct 5 ms 5228 KB Output is correct
35 Correct 5 ms 5228 KB Output is correct
36 Correct 17 ms 7728 KB Output is correct
37 Correct 218 ms 27876 KB Output is correct
38 Correct 206 ms 27616 KB Output is correct
39 Correct 207 ms 27108 KB Output is correct
40 Correct 202 ms 26228 KB Output is correct
41 Correct 184 ms 25824 KB Output is correct
42 Correct 170 ms 23800 KB Output is correct
43 Correct 226 ms 28512 KB Output is correct
44 Correct 234 ms 28384 KB Output is correct
45 Correct 112 ms 19680 KB Output is correct
46 Correct 186 ms 25860 KB Output is correct
47 Correct 23 ms 8112 KB Output is correct
48 Correct 296 ms 32716 KB Output is correct
49 Correct 294 ms 32132 KB Output is correct
50 Correct 289 ms 32072 KB Output is correct
51 Correct 303 ms 31596 KB Output is correct
52 Correct 261 ms 29844 KB Output is correct
53 Correct 185 ms 24660 KB Output is correct
54 Correct 297 ms 33480 KB Output is correct
55 Correct 341 ms 33480 KB Output is correct
56 Correct 250 ms 25160 KB Output is correct
57 Correct 277 ms 31048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 5004 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 4 ms 4972 KB Output is correct
5 Correct 5 ms 5100 KB Output is correct
6 Correct 5 ms 5228 KB Output is correct
7 Correct 5 ms 5228 KB Output is correct
8 Correct 5 ms 5228 KB Output is correct
9 Correct 5 ms 5228 KB Output is correct
10 Correct 180 ms 23636 KB Output is correct
11 Correct 224 ms 27236 KB Output is correct
12 Correct 227 ms 26848 KB Output is correct
13 Correct 226 ms 28108 KB Output is correct
14 Correct 122 ms 20704 KB Output is correct
15 Correct 165 ms 23652 KB Output is correct
16 Correct 295 ms 31852 KB Output is correct
17 Correct 283 ms 31120 KB Output is correct
18 Correct 326 ms 32712 KB Output is correct
19 Correct 201 ms 24776 KB Output is correct
20 Correct 170 ms 22788 KB Output is correct
21 Correct 189 ms 23128 KB Output is correct
22 Correct 179 ms 23416 KB Output is correct
23 Correct 175 ms 23112 KB Output is correct
24 Correct 175 ms 23264 KB Output is correct
25 Correct 168 ms 22800 KB Output is correct
26 Correct 182 ms 23136 KB Output is correct
27 Correct 173 ms 22696 KB Output is correct
28 Correct 5 ms 5228 KB Output is correct
29 Correct 5 ms 5228 KB Output is correct
30 Correct 5 ms 5228 KB Output is correct
31 Correct 4 ms 5228 KB Output is correct
32 Correct 5 ms 5228 KB Output is correct
33 Correct 6 ms 5228 KB Output is correct
34 Correct 5 ms 5228 KB Output is correct
35 Correct 5 ms 5228 KB Output is correct
36 Correct 5 ms 5228 KB Output is correct
37 Correct 17 ms 7728 KB Output is correct
38 Correct 218 ms 27876 KB Output is correct
39 Correct 206 ms 27616 KB Output is correct
40 Correct 207 ms 27108 KB Output is correct
41 Correct 202 ms 26228 KB Output is correct
42 Correct 184 ms 25824 KB Output is correct
43 Correct 170 ms 23800 KB Output is correct
44 Correct 226 ms 28512 KB Output is correct
45 Correct 234 ms 28384 KB Output is correct
46 Correct 112 ms 19680 KB Output is correct
47 Correct 186 ms 25860 KB Output is correct
48 Correct 23 ms 8112 KB Output is correct
49 Correct 296 ms 32716 KB Output is correct
50 Correct 294 ms 32132 KB Output is correct
51 Correct 289 ms 32072 KB Output is correct
52 Correct 303 ms 31596 KB Output is correct
53 Correct 261 ms 29844 KB Output is correct
54 Correct 185 ms 24660 KB Output is correct
55 Correct 297 ms 33480 KB Output is correct
56 Correct 341 ms 33480 KB Output is correct
57 Correct 250 ms 25160 KB Output is correct
58 Correct 277 ms 31048 KB Output is correct
59 Correct 79 ms 13612 KB Output is correct
60 Correct 289 ms 32868 KB Output is correct
61 Correct 298 ms 32476 KB Output is correct
62 Correct 304 ms 33864 KB Output is correct
63 Correct 206 ms 26184 KB Output is correct
64 Correct 5 ms 5100 KB Output is correct
65 Correct 5 ms 5228 KB Output is correct
66 Correct 5 ms 5228 KB Output is correct
67 Correct 5 ms 5100 KB Output is correct
68 Correct 4 ms 5100 KB Output is correct
69 Correct 5 ms 5228 KB Output is correct
70 Correct 5 ms 5228 KB Output is correct
71 Correct 5 ms 5228 KB Output is correct
72 Correct 4 ms 5100 KB Output is correct
73 Correct 5 ms 5228 KB Output is correct
74 Correct 150 ms 21984 KB Output is correct
75 Correct 206 ms 27452 KB Output is correct
76 Correct 177 ms 24036 KB Output is correct
77 Correct 144 ms 21472 KB Output is correct
78 Correct 77 ms 14820 KB Output is correct
79 Correct 62 ms 12392 KB Output is correct
80 Correct 120 ms 19040 KB Output is correct
81 Correct 241 ms 30428 KB Output is correct
82 Correct 218 ms 26844 KB Output is correct
83 Correct 271 ms 33752 KB Output is correct
84 Correct 114 ms 19936 KB Output is correct
85 Correct 187 ms 25564 KB Output is correct
86 Correct 67 ms 12348 KB Output is correct
87 Correct 311 ms 31724 KB Output is correct
88 Correct 308 ms 32040 KB Output is correct
89 Correct 256 ms 25436 KB Output is correct
90 Correct 166 ms 18528 KB Output is correct
91 Correct 175 ms 18916 KB Output is correct
92 Correct 207 ms 23976 KB Output is correct
93 Correct 361 ms 34452 KB Output is correct
94 Correct 312 ms 31828 KB Output is correct
95 Correct 370 ms 38152 KB Output is correct
96 Correct 206 ms 25032 KB Output is correct
97 Correct 262 ms 28824 KB Output is correct