#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
const int MAX=1e5+5;
int P[MAX];
bool isLine[MAX];
ii segs[MAX];
vector<int> S[MAX];
vector<iii> edges;
vector<ii> history[MAX];
int find(int u) {
if(P[u]==u)
return u;
return P[u]=find(P[u]);
}
ii getNewSeg(ii s1,ii s2,int u,int v) {
if(s1.first==u) {
if(s2.first==v)
return {s1.second,s2.second};
if(s2.second==v)
return {s1.second,s2.first};
} else if(s1.second==u) {
if(s2.first==v)
return {s1.first,s2.second};
if(s2.second==v)
return {s1.first,s2.first};
}
return {-1,-1};
}
void merge(int u,int v,int w,int rootU,int rootV) {
if(S[u].size()<S[v].size()) {
swap(u,v);
swap(rootU,rootV);
}
P[v]=u;
segs[u]=getNewSeg(segs[u],segs[v],rootU,rootV);
bool newIsLine=(segs[u].first!=-1);
if(isLine[u]!=newIsLine) {
isLine[u]=false;
for(int tmp:S[u])
history[tmp].push_back({w,u});
}
while(S[v].size()>0) {
int tmp=S[v].back();
S[v].pop_back();
S[u].push_back(tmp);
if(!newIsLine)
history[tmp].push_back({w,u});
}
}
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
for(int i=0;i<M;i++)
edges.push_back({W[i],{U[i],V[i]}});
sort(edges.begin(),edges.end());
for(int i=0;i<N;i++) {
P[i]=i;
isLine[i]=true;
segs[i]={i,i};
S[i].push_back(i);
}
for(iii edge:edges) {
int u=find(edge.second.first),v=find(edge.second.second),w=edge.first;
if(u!=v)
merge(u,v,w,edge.second.first,edge.second.second);
else if(isLine[u]) {
isLine[u]=false;
segs[u]={-1,-1};
for(int tmp:S[u])
history[tmp].push_back({w,u});
}
}
}
int getMinimumFuelCapacity(int X, int Y) {
vector<ii> hisX=history[X],hisY=history[Y];
int rs=-1;
while(hisX.size()>0&&hisY.size()>0&&hisX.back().second==hisY.back().second) {
rs=max(hisX.back().first,hisY.back().first);
hisX.pop_back(),hisY.pop_back();
}
return rs;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4928 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4972 KB |
Output is correct |
5 |
Correct |
4 ms |
5068 KB |
Output is correct |
6 |
Correct |
4 ms |
5068 KB |
Output is correct |
7 |
Correct |
4 ms |
5068 KB |
Output is correct |
8 |
Correct |
4 ms |
5068 KB |
Output is correct |
9 |
Correct |
64 ms |
14520 KB |
Output is correct |
10 |
Correct |
82 ms |
16184 KB |
Output is correct |
11 |
Correct |
72 ms |
16096 KB |
Output is correct |
12 |
Correct |
79 ms |
16788 KB |
Output is correct |
13 |
Correct |
63 ms |
14136 KB |
Output is correct |
14 |
Correct |
70 ms |
14492 KB |
Output is correct |
15 |
Correct |
158 ms |
18556 KB |
Output is correct |
16 |
Correct |
145 ms |
18068 KB |
Output is correct |
17 |
Correct |
152 ms |
18720 KB |
Output is correct |
18 |
Correct |
133 ms |
15776 KB |
Output is correct |
19 |
Correct |
76 ms |
10504 KB |
Output is correct |
20 |
Correct |
193 ms |
21244 KB |
Output is correct |
21 |
Correct |
173 ms |
20976 KB |
Output is correct |
22 |
Correct |
202 ms |
21908 KB |
Output is correct |
23 |
Correct |
168 ms |
19896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4928 KB |
Output is correct |
3 |
Correct |
175 ms |
18816 KB |
Output is correct |
4 |
Correct |
196 ms |
19340 KB |
Output is correct |
5 |
Correct |
186 ms |
19196 KB |
Output is correct |
6 |
Correct |
168 ms |
19160 KB |
Output is correct |
7 |
Correct |
197 ms |
19328 KB |
Output is correct |
8 |
Correct |
173 ms |
18812 KB |
Output is correct |
9 |
Correct |
190 ms |
19068 KB |
Output is correct |
10 |
Correct |
193 ms |
18692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4928 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4972 KB |
Output is correct |
5 |
Correct |
4 ms |
5068 KB |
Output is correct |
6 |
Correct |
4 ms |
5068 KB |
Output is correct |
7 |
Correct |
4 ms |
5068 KB |
Output is correct |
8 |
Correct |
4 ms |
5068 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
4 ms |
5068 KB |
Output is correct |
11 |
Correct |
4 ms |
5068 KB |
Output is correct |
12 |
Correct |
4 ms |
5068 KB |
Output is correct |
13 |
Correct |
5 ms |
5068 KB |
Output is correct |
14 |
Correct |
5 ms |
5068 KB |
Output is correct |
15 |
Correct |
4 ms |
5068 KB |
Output is correct |
16 |
Correct |
4 ms |
5068 KB |
Output is correct |
17 |
Correct |
4 ms |
5068 KB |
Output is correct |
18 |
Correct |
5 ms |
5068 KB |
Output is correct |
19 |
Correct |
4 ms |
5068 KB |
Output is correct |
20 |
Correct |
4 ms |
5068 KB |
Output is correct |
21 |
Correct |
4 ms |
5068 KB |
Output is correct |
22 |
Correct |
4 ms |
5068 KB |
Output is correct |
23 |
Correct |
3 ms |
5068 KB |
Output is correct |
24 |
Correct |
5 ms |
5104 KB |
Output is correct |
25 |
Correct |
6 ms |
5068 KB |
Output is correct |
26 |
Correct |
5 ms |
5068 KB |
Output is correct |
27 |
Correct |
4 ms |
5068 KB |
Output is correct |
28 |
Correct |
4 ms |
5068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4928 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4972 KB |
Output is correct |
6 |
Correct |
4 ms |
5068 KB |
Output is correct |
7 |
Correct |
4 ms |
5068 KB |
Output is correct |
8 |
Correct |
4 ms |
5068 KB |
Output is correct |
9 |
Correct |
4 ms |
5068 KB |
Output is correct |
10 |
Correct |
64 ms |
14520 KB |
Output is correct |
11 |
Correct |
82 ms |
16184 KB |
Output is correct |
12 |
Correct |
72 ms |
16096 KB |
Output is correct |
13 |
Correct |
79 ms |
16788 KB |
Output is correct |
14 |
Correct |
63 ms |
14136 KB |
Output is correct |
15 |
Correct |
4 ms |
5068 KB |
Output is correct |
16 |
Correct |
4 ms |
5068 KB |
Output is correct |
17 |
Correct |
4 ms |
5068 KB |
Output is correct |
18 |
Correct |
5 ms |
5068 KB |
Output is correct |
19 |
Correct |
5 ms |
5068 KB |
Output is correct |
20 |
Correct |
4 ms |
5068 KB |
Output is correct |
21 |
Correct |
4 ms |
5068 KB |
Output is correct |
22 |
Correct |
4 ms |
5068 KB |
Output is correct |
23 |
Correct |
5 ms |
5068 KB |
Output is correct |
24 |
Correct |
4 ms |
5068 KB |
Output is correct |
25 |
Correct |
4 ms |
5068 KB |
Output is correct |
26 |
Correct |
4 ms |
5068 KB |
Output is correct |
27 |
Correct |
4 ms |
5068 KB |
Output is correct |
28 |
Correct |
3 ms |
5068 KB |
Output is correct |
29 |
Correct |
5 ms |
5104 KB |
Output is correct |
30 |
Correct |
6 ms |
5068 KB |
Output is correct |
31 |
Correct |
5 ms |
5068 KB |
Output is correct |
32 |
Correct |
4 ms |
5068 KB |
Output is correct |
33 |
Correct |
4 ms |
5068 KB |
Output is correct |
34 |
Correct |
15 ms |
7052 KB |
Output is correct |
35 |
Correct |
121 ms |
18640 KB |
Output is correct |
36 |
Correct |
144 ms |
18712 KB |
Output is correct |
37 |
Correct |
140 ms |
19404 KB |
Output is correct |
38 |
Correct |
115 ms |
19344 KB |
Output is correct |
39 |
Correct |
126 ms |
20256 KB |
Output is correct |
40 |
Correct |
123 ms |
19432 KB |
Output is correct |
41 |
Correct |
107 ms |
18964 KB |
Output is correct |
42 |
Correct |
103 ms |
18728 KB |
Output is correct |
43 |
Correct |
94 ms |
16828 KB |
Output is correct |
44 |
Correct |
143 ms |
21060 KB |
Output is correct |
45 |
Correct |
121 ms |
16976 KB |
Output is correct |
46 |
Correct |
105 ms |
18576 KB |
Output is correct |
47 |
Correct |
113 ms |
17812 KB |
Output is correct |
48 |
Correct |
140 ms |
17160 KB |
Output is correct |
49 |
Correct |
69 ms |
11828 KB |
Output is correct |
50 |
Correct |
57 ms |
9864 KB |
Output is correct |
51 |
Correct |
101 ms |
14940 KB |
Output is correct |
52 |
Correct |
155 ms |
20700 KB |
Output is correct |
53 |
Correct |
261 ms |
21932 KB |
Output is correct |
54 |
Correct |
148 ms |
22424 KB |
Output is correct |
55 |
Correct |
92 ms |
16788 KB |
Output is correct |
56 |
Correct |
194 ms |
19788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4928 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4972 KB |
Output is correct |
5 |
Correct |
4 ms |
5068 KB |
Output is correct |
6 |
Correct |
4 ms |
5068 KB |
Output is correct |
7 |
Correct |
4 ms |
5068 KB |
Output is correct |
8 |
Correct |
4 ms |
5068 KB |
Output is correct |
9 |
Correct |
64 ms |
14520 KB |
Output is correct |
10 |
Correct |
82 ms |
16184 KB |
Output is correct |
11 |
Correct |
72 ms |
16096 KB |
Output is correct |
12 |
Correct |
79 ms |
16788 KB |
Output is correct |
13 |
Correct |
63 ms |
14136 KB |
Output is correct |
14 |
Correct |
70 ms |
14492 KB |
Output is correct |
15 |
Correct |
158 ms |
18556 KB |
Output is correct |
16 |
Correct |
145 ms |
18068 KB |
Output is correct |
17 |
Correct |
152 ms |
18720 KB |
Output is correct |
18 |
Correct |
133 ms |
15776 KB |
Output is correct |
19 |
Correct |
175 ms |
18816 KB |
Output is correct |
20 |
Correct |
196 ms |
19340 KB |
Output is correct |
21 |
Correct |
186 ms |
19196 KB |
Output is correct |
22 |
Correct |
168 ms |
19160 KB |
Output is correct |
23 |
Correct |
197 ms |
19328 KB |
Output is correct |
24 |
Correct |
173 ms |
18812 KB |
Output is correct |
25 |
Correct |
190 ms |
19068 KB |
Output is correct |
26 |
Correct |
193 ms |
18692 KB |
Output is correct |
27 |
Correct |
4 ms |
5068 KB |
Output is correct |
28 |
Correct |
4 ms |
5068 KB |
Output is correct |
29 |
Correct |
4 ms |
5068 KB |
Output is correct |
30 |
Correct |
5 ms |
5068 KB |
Output is correct |
31 |
Correct |
5 ms |
5068 KB |
Output is correct |
32 |
Correct |
4 ms |
5068 KB |
Output is correct |
33 |
Correct |
4 ms |
5068 KB |
Output is correct |
34 |
Correct |
4 ms |
5068 KB |
Output is correct |
35 |
Correct |
5 ms |
5068 KB |
Output is correct |
36 |
Correct |
15 ms |
7052 KB |
Output is correct |
37 |
Correct |
121 ms |
18640 KB |
Output is correct |
38 |
Correct |
144 ms |
18712 KB |
Output is correct |
39 |
Correct |
140 ms |
19404 KB |
Output is correct |
40 |
Correct |
115 ms |
19344 KB |
Output is correct |
41 |
Correct |
126 ms |
20256 KB |
Output is correct |
42 |
Correct |
123 ms |
19432 KB |
Output is correct |
43 |
Correct |
107 ms |
18964 KB |
Output is correct |
44 |
Correct |
103 ms |
18728 KB |
Output is correct |
45 |
Correct |
94 ms |
16828 KB |
Output is correct |
46 |
Correct |
143 ms |
21060 KB |
Output is correct |
47 |
Correct |
23 ms |
7256 KB |
Output is correct |
48 |
Correct |
197 ms |
21280 KB |
Output is correct |
49 |
Correct |
202 ms |
21408 KB |
Output is correct |
50 |
Correct |
224 ms |
22016 KB |
Output is correct |
51 |
Correct |
215 ms |
22392 KB |
Output is correct |
52 |
Correct |
284 ms |
22064 KB |
Output is correct |
53 |
Correct |
170 ms |
19116 KB |
Output is correct |
54 |
Correct |
187 ms |
21884 KB |
Output is correct |
55 |
Correct |
186 ms |
21388 KB |
Output is correct |
56 |
Correct |
225 ms |
19416 KB |
Output is correct |
57 |
Correct |
247 ms |
23968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4928 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4972 KB |
Output is correct |
6 |
Correct |
4 ms |
5068 KB |
Output is correct |
7 |
Correct |
4 ms |
5068 KB |
Output is correct |
8 |
Correct |
4 ms |
5068 KB |
Output is correct |
9 |
Correct |
4 ms |
5068 KB |
Output is correct |
10 |
Correct |
64 ms |
14520 KB |
Output is correct |
11 |
Correct |
82 ms |
16184 KB |
Output is correct |
12 |
Correct |
72 ms |
16096 KB |
Output is correct |
13 |
Correct |
79 ms |
16788 KB |
Output is correct |
14 |
Correct |
63 ms |
14136 KB |
Output is correct |
15 |
Correct |
70 ms |
14492 KB |
Output is correct |
16 |
Correct |
158 ms |
18556 KB |
Output is correct |
17 |
Correct |
145 ms |
18068 KB |
Output is correct |
18 |
Correct |
152 ms |
18720 KB |
Output is correct |
19 |
Correct |
133 ms |
15776 KB |
Output is correct |
20 |
Correct |
175 ms |
18816 KB |
Output is correct |
21 |
Correct |
196 ms |
19340 KB |
Output is correct |
22 |
Correct |
186 ms |
19196 KB |
Output is correct |
23 |
Correct |
168 ms |
19160 KB |
Output is correct |
24 |
Correct |
197 ms |
19328 KB |
Output is correct |
25 |
Correct |
173 ms |
18812 KB |
Output is correct |
26 |
Correct |
190 ms |
19068 KB |
Output is correct |
27 |
Correct |
193 ms |
18692 KB |
Output is correct |
28 |
Correct |
4 ms |
5068 KB |
Output is correct |
29 |
Correct |
4 ms |
5068 KB |
Output is correct |
30 |
Correct |
4 ms |
5068 KB |
Output is correct |
31 |
Correct |
5 ms |
5068 KB |
Output is correct |
32 |
Correct |
5 ms |
5068 KB |
Output is correct |
33 |
Correct |
4 ms |
5068 KB |
Output is correct |
34 |
Correct |
4 ms |
5068 KB |
Output is correct |
35 |
Correct |
4 ms |
5068 KB |
Output is correct |
36 |
Correct |
5 ms |
5068 KB |
Output is correct |
37 |
Correct |
15 ms |
7052 KB |
Output is correct |
38 |
Correct |
121 ms |
18640 KB |
Output is correct |
39 |
Correct |
144 ms |
18712 KB |
Output is correct |
40 |
Correct |
140 ms |
19404 KB |
Output is correct |
41 |
Correct |
115 ms |
19344 KB |
Output is correct |
42 |
Correct |
126 ms |
20256 KB |
Output is correct |
43 |
Correct |
123 ms |
19432 KB |
Output is correct |
44 |
Correct |
107 ms |
18964 KB |
Output is correct |
45 |
Correct |
103 ms |
18728 KB |
Output is correct |
46 |
Correct |
94 ms |
16828 KB |
Output is correct |
47 |
Correct |
143 ms |
21060 KB |
Output is correct |
48 |
Correct |
23 ms |
7256 KB |
Output is correct |
49 |
Correct |
197 ms |
21280 KB |
Output is correct |
50 |
Correct |
202 ms |
21408 KB |
Output is correct |
51 |
Correct |
224 ms |
22016 KB |
Output is correct |
52 |
Correct |
215 ms |
22392 KB |
Output is correct |
53 |
Correct |
284 ms |
22064 KB |
Output is correct |
54 |
Correct |
170 ms |
19116 KB |
Output is correct |
55 |
Correct |
187 ms |
21884 KB |
Output is correct |
56 |
Correct |
186 ms |
21388 KB |
Output is correct |
57 |
Correct |
225 ms |
19416 KB |
Output is correct |
58 |
Correct |
247 ms |
23968 KB |
Output is correct |
59 |
Correct |
76 ms |
10504 KB |
Output is correct |
60 |
Correct |
193 ms |
21244 KB |
Output is correct |
61 |
Correct |
173 ms |
20976 KB |
Output is correct |
62 |
Correct |
202 ms |
21908 KB |
Output is correct |
63 |
Correct |
168 ms |
19896 KB |
Output is correct |
64 |
Correct |
4 ms |
5068 KB |
Output is correct |
65 |
Correct |
4 ms |
5068 KB |
Output is correct |
66 |
Correct |
4 ms |
5068 KB |
Output is correct |
67 |
Correct |
4 ms |
5068 KB |
Output is correct |
68 |
Correct |
3 ms |
5068 KB |
Output is correct |
69 |
Correct |
5 ms |
5104 KB |
Output is correct |
70 |
Correct |
6 ms |
5068 KB |
Output is correct |
71 |
Correct |
5 ms |
5068 KB |
Output is correct |
72 |
Correct |
4 ms |
5068 KB |
Output is correct |
73 |
Correct |
4 ms |
5068 KB |
Output is correct |
74 |
Correct |
121 ms |
16976 KB |
Output is correct |
75 |
Correct |
105 ms |
18576 KB |
Output is correct |
76 |
Correct |
113 ms |
17812 KB |
Output is correct |
77 |
Correct |
140 ms |
17160 KB |
Output is correct |
78 |
Correct |
69 ms |
11828 KB |
Output is correct |
79 |
Correct |
57 ms |
9864 KB |
Output is correct |
80 |
Correct |
101 ms |
14940 KB |
Output is correct |
81 |
Correct |
155 ms |
20700 KB |
Output is correct |
82 |
Correct |
261 ms |
21932 KB |
Output is correct |
83 |
Correct |
148 ms |
22424 KB |
Output is correct |
84 |
Correct |
92 ms |
16788 KB |
Output is correct |
85 |
Correct |
194 ms |
19788 KB |
Output is correct |
86 |
Correct |
74 ms |
9856 KB |
Output is correct |
87 |
Correct |
236 ms |
20984 KB |
Output is correct |
88 |
Correct |
201 ms |
21532 KB |
Output is correct |
89 |
Correct |
205 ms |
19224 KB |
Output is correct |
90 |
Correct |
168 ms |
13644 KB |
Output is correct |
91 |
Correct |
150 ms |
13688 KB |
Output is correct |
92 |
Correct |
182 ms |
17720 KB |
Output is correct |
93 |
Correct |
237 ms |
22904 KB |
Output is correct |
94 |
Correct |
265 ms |
24080 KB |
Output is correct |
95 |
Correct |
241 ms |
24232 KB |
Output is correct |
96 |
Correct |
191 ms |
19560 KB |
Output is correct |
97 |
Correct |
225 ms |
21356 KB |
Output is correct |