Submission #1030197

# Submission time Handle Problem Language Result Execution time Memory
1030197 2024-07-21T22:52:36 Z vjudge1 Swapping Cities (APIO20_swap) C++17
100 / 100
415 ms 63176 KB
#include "swap.h"

#include <bits/stdc++.h>
using namespace std;
vector<tuple<int,int,int>> edg;
int minyes[100100],abp[100100];
map<int,int> unpersist[100100];
vector<int>v[100100];
vector<pair<int,int>> roots;
int derot,N_;
void upd(int t,int p,int v){
    unpersist[p][t]=v;
}
void do_a_merge(int &x,int &y,int t){
    if(v[x].size()<v[y].size())
        swap(x,y);
    for(auto k:v[y])
        upd(t,k,x),abp[k]=x,v[x].push_back(k);
    v[y].clear();
}
int par[100100],deg[100100];
bitset<100100>yes;
void init(int N,int M,vector<int>U,vector<int>V,vector<int>W) {
    for(int i=1;i<=N;i++)
        unpersist[i][-1]=i,abp[i]=i;
    N_=N;
    for(int i=1;i<=N;i++)
        v[i].push_back(i);
    for(int i=0;i<M;i++)
        edg.push_back({W[i],++U[i],++V[i]});
    for(auto&i:minyes)i=1e9+1;
    sort(edg.begin(),edg.end());
    int prevW=get<0>(edg[0]);
    for(auto[w,u,v]:edg){
        deg[u]++,deg[v]++;
        if(deg[u]>2&&!yes[abp[u]])
            yes[abp[u]]=1,minyes[abp[u]]=w;
        if(deg[v]>2&&!yes[abp[v]])
            yes[abp[v]]=1,minyes[abp[v]]=w;
        u=abp[u],v=abp[v];
        if(u-v) {
            do_a_merge(u,v,w);
            if(!yes[u]&&yes[v])
                yes[u]=1,minyes[u]=w;
        } else if(!yes[v])
            yes[v]=1,minyes[v]=w;
        prevW=w;
    }
}
int ok(int t,int x,int y){
    x=(--unpersist[x].upper_bound(t))->second;
    y=(--unpersist[y].upper_bound(t))->second;
    return x==y&&minyes[x]<=t;
}
int getMinimumFuelCapacity(int X,int Y) {
    ++X,++Y;
    int l=1,r=1e9,res=-1;
    while(l<=r){
        int mid=l+r>>1;
        if(ok(mid,X,Y)){
            r=mid-1,res=mid;
        } else {
            l=mid+1;
        }
    }
    return res;
}

Compilation message

swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:33:9: warning: variable 'prevW' set but not used [-Wunused-but-set-variable]
   33 |     int prevW=get<0>(edg[0]);
      |         ^~~~~
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:59:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |         int mid=l+r>>1;
      |                 ~^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7772 KB Output is correct
2 Correct 3 ms 7772 KB Output is correct
3 Correct 3 ms 7880 KB Output is correct
4 Correct 3 ms 8028 KB Output is correct
5 Correct 4 ms 8024 KB Output is correct
6 Correct 4 ms 8028 KB Output is correct
7 Correct 4 ms 8028 KB Output is correct
8 Correct 3 ms 8028 KB Output is correct
9 Correct 127 ms 43060 KB Output is correct
10 Correct 164 ms 50116 KB Output is correct
11 Correct 144 ms 49292 KB Output is correct
12 Correct 177 ms 52308 KB Output is correct
13 Correct 77 ms 29648 KB Output is correct
14 Correct 124 ms 42952 KB Output is correct
15 Correct 406 ms 55636 KB Output is correct
16 Correct 371 ms 53884 KB Output is correct
17 Correct 412 ms 57036 KB Output is correct
18 Correct 164 ms 33840 KB Output is correct
19 Correct 133 ms 19044 KB Output is correct
20 Correct 378 ms 56556 KB Output is correct
21 Correct 360 ms 55172 KB Output is correct
22 Correct 366 ms 58160 KB Output is correct
23 Correct 166 ms 35120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7772 KB Output is correct
2 Correct 3 ms 7772 KB Output is correct
3 Correct 184 ms 30824 KB Output is correct
4 Correct 173 ms 31792 KB Output is correct
5 Correct 202 ms 31448 KB Output is correct
6 Correct 172 ms 31540 KB Output is correct
7 Correct 188 ms 31564 KB Output is correct
8 Correct 198 ms 30748 KB Output is correct
9 Correct 176 ms 31304 KB Output is correct
10 Correct 184 ms 30844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7772 KB Output is correct
2 Correct 3 ms 7772 KB Output is correct
3 Correct 3 ms 7880 KB Output is correct
4 Correct 3 ms 8028 KB Output is correct
5 Correct 4 ms 8024 KB Output is correct
6 Correct 4 ms 8028 KB Output is correct
7 Correct 4 ms 8028 KB Output is correct
8 Correct 3 ms 8028 KB Output is correct
9 Correct 3 ms 7772 KB Output is correct
10 Correct 4 ms 8028 KB Output is correct
11 Correct 4 ms 8024 KB Output is correct
12 Correct 3 ms 8028 KB Output is correct
13 Correct 3 ms 8028 KB Output is correct
14 Correct 3 ms 8028 KB Output is correct
15 Correct 3 ms 8028 KB Output is correct
16 Correct 4 ms 8028 KB Output is correct
17 Correct 4 ms 7956 KB Output is correct
18 Correct 4 ms 8028 KB Output is correct
19 Correct 3 ms 8028 KB Output is correct
20 Correct 4 ms 8116 KB Output is correct
21 Correct 3 ms 8028 KB Output is correct
22 Correct 3 ms 8028 KB Output is correct
23 Correct 4 ms 8028 KB Output is correct
24 Correct 3 ms 8028 KB Output is correct
25 Correct 3 ms 8028 KB Output is correct
26 Correct 4 ms 8284 KB Output is correct
27 Correct 4 ms 8044 KB Output is correct
28 Correct 3 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7772 KB Output is correct
2 Correct 3 ms 7772 KB Output is correct
3 Correct 3 ms 7772 KB Output is correct
4 Correct 3 ms 7880 KB Output is correct
5 Correct 3 ms 8028 KB Output is correct
6 Correct 4 ms 8024 KB Output is correct
7 Correct 4 ms 8028 KB Output is correct
8 Correct 4 ms 8028 KB Output is correct
9 Correct 3 ms 8028 KB Output is correct
10 Correct 127 ms 43060 KB Output is correct
11 Correct 164 ms 50116 KB Output is correct
12 Correct 144 ms 49292 KB Output is correct
13 Correct 177 ms 52308 KB Output is correct
14 Correct 77 ms 29648 KB Output is correct
15 Correct 4 ms 8028 KB Output is correct
16 Correct 4 ms 8024 KB Output is correct
17 Correct 3 ms 8028 KB Output is correct
18 Correct 3 ms 8028 KB Output is correct
19 Correct 3 ms 8028 KB Output is correct
20 Correct 3 ms 8028 KB Output is correct
21 Correct 4 ms 8028 KB Output is correct
22 Correct 4 ms 7956 KB Output is correct
23 Correct 4 ms 8028 KB Output is correct
24 Correct 3 ms 8028 KB Output is correct
25 Correct 4 ms 8116 KB Output is correct
26 Correct 3 ms 8028 KB Output is correct
27 Correct 3 ms 8028 KB Output is correct
28 Correct 4 ms 8028 KB Output is correct
29 Correct 3 ms 8028 KB Output is correct
30 Correct 3 ms 8028 KB Output is correct
31 Correct 4 ms 8284 KB Output is correct
32 Correct 4 ms 8044 KB Output is correct
33 Correct 3 ms 8028 KB Output is correct
34 Correct 20 ms 12548 KB Output is correct
35 Correct 163 ms 51404 KB Output is correct
36 Correct 150 ms 50380 KB Output is correct
37 Correct 142 ms 48840 KB Output is correct
38 Correct 133 ms 46036 KB Output is correct
39 Correct 113 ms 44996 KB Output is correct
40 Correct 95 ms 40360 KB Output is correct
41 Correct 166 ms 53212 KB Output is correct
42 Correct 203 ms 52984 KB Output is correct
43 Correct 61 ms 28612 KB Output is correct
44 Correct 133 ms 43988 KB Output is correct
45 Correct 76 ms 31296 KB Output is correct
46 Correct 163 ms 50628 KB Output is correct
47 Correct 101 ms 39880 KB Output is correct
48 Correct 92 ms 32568 KB Output is correct
49 Correct 42 ms 17100 KB Output is correct
50 Correct 34 ms 15816 KB Output is correct
51 Correct 61 ms 27336 KB Output is correct
52 Correct 152 ms 51136 KB Output is correct
53 Correct 109 ms 40128 KB Output is correct
54 Correct 201 ms 58052 KB Output is correct
55 Correct 69 ms 28948 KB Output is correct
56 Correct 98 ms 37320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7772 KB Output is correct
2 Correct 3 ms 7772 KB Output is correct
3 Correct 3 ms 7880 KB Output is correct
4 Correct 3 ms 8028 KB Output is correct
5 Correct 4 ms 8024 KB Output is correct
6 Correct 4 ms 8028 KB Output is correct
7 Correct 4 ms 8028 KB Output is correct
8 Correct 3 ms 8028 KB Output is correct
9 Correct 127 ms 43060 KB Output is correct
10 Correct 164 ms 50116 KB Output is correct
11 Correct 144 ms 49292 KB Output is correct
12 Correct 177 ms 52308 KB Output is correct
13 Correct 77 ms 29648 KB Output is correct
14 Correct 124 ms 42952 KB Output is correct
15 Correct 406 ms 55636 KB Output is correct
16 Correct 371 ms 53884 KB Output is correct
17 Correct 412 ms 57036 KB Output is correct
18 Correct 164 ms 33840 KB Output is correct
19 Correct 184 ms 30824 KB Output is correct
20 Correct 173 ms 31792 KB Output is correct
21 Correct 202 ms 31448 KB Output is correct
22 Correct 172 ms 31540 KB Output is correct
23 Correct 188 ms 31564 KB Output is correct
24 Correct 198 ms 30748 KB Output is correct
25 Correct 176 ms 31304 KB Output is correct
26 Correct 184 ms 30844 KB Output is correct
27 Correct 4 ms 8028 KB Output is correct
28 Correct 4 ms 8024 KB Output is correct
29 Correct 3 ms 8028 KB Output is correct
30 Correct 3 ms 8028 KB Output is correct
31 Correct 3 ms 8028 KB Output is correct
32 Correct 3 ms 8028 KB Output is correct
33 Correct 4 ms 8028 KB Output is correct
34 Correct 4 ms 7956 KB Output is correct
35 Correct 4 ms 8028 KB Output is correct
36 Correct 20 ms 12548 KB Output is correct
37 Correct 163 ms 51404 KB Output is correct
38 Correct 150 ms 50380 KB Output is correct
39 Correct 142 ms 48840 KB Output is correct
40 Correct 133 ms 46036 KB Output is correct
41 Correct 113 ms 44996 KB Output is correct
42 Correct 95 ms 40360 KB Output is correct
43 Correct 166 ms 53212 KB Output is correct
44 Correct 203 ms 52984 KB Output is correct
45 Correct 61 ms 28612 KB Output is correct
46 Correct 133 ms 43988 KB Output is correct
47 Correct 26 ms 12576 KB Output is correct
48 Correct 325 ms 56624 KB Output is correct
49 Correct 319 ms 54688 KB Output is correct
50 Correct 312 ms 54328 KB Output is correct
51 Correct 295 ms 52176 KB Output is correct
52 Correct 254 ms 47992 KB Output is correct
53 Correct 233 ms 37044 KB Output is correct
54 Correct 312 ms 57144 KB Output is correct
55 Correct 319 ms 58220 KB Output is correct
56 Correct 167 ms 34036 KB Output is correct
57 Correct 272 ms 48608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7772 KB Output is correct
2 Correct 3 ms 7772 KB Output is correct
3 Correct 3 ms 7772 KB Output is correct
4 Correct 3 ms 7880 KB Output is correct
5 Correct 3 ms 8028 KB Output is correct
6 Correct 4 ms 8024 KB Output is correct
7 Correct 4 ms 8028 KB Output is correct
8 Correct 4 ms 8028 KB Output is correct
9 Correct 3 ms 8028 KB Output is correct
10 Correct 127 ms 43060 KB Output is correct
11 Correct 164 ms 50116 KB Output is correct
12 Correct 144 ms 49292 KB Output is correct
13 Correct 177 ms 52308 KB Output is correct
14 Correct 77 ms 29648 KB Output is correct
15 Correct 124 ms 42952 KB Output is correct
16 Correct 406 ms 55636 KB Output is correct
17 Correct 371 ms 53884 KB Output is correct
18 Correct 412 ms 57036 KB Output is correct
19 Correct 164 ms 33840 KB Output is correct
20 Correct 184 ms 30824 KB Output is correct
21 Correct 173 ms 31792 KB Output is correct
22 Correct 202 ms 31448 KB Output is correct
23 Correct 172 ms 31540 KB Output is correct
24 Correct 188 ms 31564 KB Output is correct
25 Correct 198 ms 30748 KB Output is correct
26 Correct 176 ms 31304 KB Output is correct
27 Correct 184 ms 30844 KB Output is correct
28 Correct 4 ms 8028 KB Output is correct
29 Correct 4 ms 8024 KB Output is correct
30 Correct 3 ms 8028 KB Output is correct
31 Correct 3 ms 8028 KB Output is correct
32 Correct 3 ms 8028 KB Output is correct
33 Correct 3 ms 8028 KB Output is correct
34 Correct 4 ms 8028 KB Output is correct
35 Correct 4 ms 7956 KB Output is correct
36 Correct 4 ms 8028 KB Output is correct
37 Correct 20 ms 12548 KB Output is correct
38 Correct 163 ms 51404 KB Output is correct
39 Correct 150 ms 50380 KB Output is correct
40 Correct 142 ms 48840 KB Output is correct
41 Correct 133 ms 46036 KB Output is correct
42 Correct 113 ms 44996 KB Output is correct
43 Correct 95 ms 40360 KB Output is correct
44 Correct 166 ms 53212 KB Output is correct
45 Correct 203 ms 52984 KB Output is correct
46 Correct 61 ms 28612 KB Output is correct
47 Correct 133 ms 43988 KB Output is correct
48 Correct 26 ms 12576 KB Output is correct
49 Correct 325 ms 56624 KB Output is correct
50 Correct 319 ms 54688 KB Output is correct
51 Correct 312 ms 54328 KB Output is correct
52 Correct 295 ms 52176 KB Output is correct
53 Correct 254 ms 47992 KB Output is correct
54 Correct 233 ms 37044 KB Output is correct
55 Correct 312 ms 57144 KB Output is correct
56 Correct 319 ms 58220 KB Output is correct
57 Correct 167 ms 34036 KB Output is correct
58 Correct 272 ms 48608 KB Output is correct
59 Correct 133 ms 19044 KB Output is correct
60 Correct 378 ms 56556 KB Output is correct
61 Correct 360 ms 55172 KB Output is correct
62 Correct 366 ms 58160 KB Output is correct
63 Correct 166 ms 35120 KB Output is correct
64 Correct 3 ms 8028 KB Output is correct
65 Correct 4 ms 8116 KB Output is correct
66 Correct 3 ms 8028 KB Output is correct
67 Correct 3 ms 8028 KB Output is correct
68 Correct 4 ms 8028 KB Output is correct
69 Correct 3 ms 8028 KB Output is correct
70 Correct 3 ms 8028 KB Output is correct
71 Correct 4 ms 8284 KB Output is correct
72 Correct 4 ms 8044 KB Output is correct
73 Correct 3 ms 8028 KB Output is correct
74 Correct 76 ms 31296 KB Output is correct
75 Correct 163 ms 50628 KB Output is correct
76 Correct 101 ms 39880 KB Output is correct
77 Correct 92 ms 32568 KB Output is correct
78 Correct 42 ms 17100 KB Output is correct
79 Correct 34 ms 15816 KB Output is correct
80 Correct 61 ms 27336 KB Output is correct
81 Correct 152 ms 51136 KB Output is correct
82 Correct 109 ms 40128 KB Output is correct
83 Correct 201 ms 58052 KB Output is correct
84 Correct 69 ms 28948 KB Output is correct
85 Correct 98 ms 37320 KB Output is correct
86 Correct 58 ms 17796 KB Output is correct
87 Correct 269 ms 52788 KB Output is correct
88 Correct 309 ms 53692 KB Output is correct
89 Correct 182 ms 36072 KB Output is correct
90 Correct 142 ms 20984 KB Output is correct
91 Correct 157 ms 22760 KB Output is correct
92 Correct 203 ms 32428 KB Output is correct
93 Correct 334 ms 53688 KB Output is correct
94 Correct 262 ms 45748 KB Output is correct
95 Correct 415 ms 63176 KB Output is correct
96 Correct 191 ms 34096 KB Output is correct
97 Correct 234 ms 40840 KB Output is correct