/*input
3 2
0 1 5
0 2 5
1
1 2
*/
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(x) x.begin(),x.end()
#define pii pair<int,int>
#define f first
#define s second
#define MXTO(a,b) a=max(a,b)
#define MNTO(a,b) a=min(a,b)
#define sz(x) (int)x.size()
#define pb push_back
const int maxn=1e5+5;
vector<pair<int,pii>> ed;
int n,m;
int par[maxn];
pair<bool,pii> cmp[maxn];
vector<int> vv[maxn];
int find(int u){
if(par[u]==u) return u;
return par[u]=find(par[u]);
}
vector<pii> sp[maxn];
int sc[maxn];
const int INF=0x3f3f3f3f;
void merge(int t,int a,int b){
int oa=a,ob=b;
a=find(a),b=find(b);
if(a==b){
if(sc[a]==INF) sc[a]=t;
cmp[a].f=0;
return;
}
if(sz(vv[a])<sz(vv[b])) swap(a,b),swap(oa,ob);
par[b]=a;
if(cmp[a].f and cmp[b].f){
if((oa==cmp[a].s.f or oa==cmp[a].s.s) and (ob==cmp[b].s.f or ob==cmp[b].s.s)){
cmp[a].f=1;
if(oa==cmp[a].s.f) cmp[a].s.f=cmp[a].s.s;
if(ob==cmp[b].s.f) cmp[a].s.s=cmp[b].s.s;
else cmp[a].s.s=cmp[b].s.f;
}
else{
if(sc[a]==INF) sc[a]=t;
cmp[a].f=0;
}
}
else{
if(sc[a]==INF) sc[a]=t;
cmp[a].f=0;
}
for(int x:vv[b]) sp[x].pb({t,a}),vv[a].pb(x);
vv[b].clear();
}
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n=N,m=M;
REP(i,M){
ed.pb({W[i],{U[i],V[i]}});
}
sort(ALL(ed));
REP(i,n) par[i]=i,cmp[i]={1,{i,i}},vv[i].pb(i),sc[i]=INF,sp[i].pb({-1,i});
REP(i,m){
auto a=ed[i];
merge(i,a.s.f,a.s.s);
}
}
int gp(int x,int t){
return (*prev(upper_bound(ALL(sp[x]),make_pair(t,INF)))).s;
}
int getMinimumFuelCapacity(int x, int y) {
int l=0,r=m-1;
int a=gp(x,m-1),b=gp(y,m-1);
if(a!=b or sc[a]==INF){
return -1;
}
while(l<r){
int mid=(l+r)/2;
int a=gp(x,mid),b=gp(y,mid);
if(a==b and sc[a]<=mid) r=mid;
else l=mid+1;
}
return ed[l].f;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
133 ms |
22524 KB |
Output is correct |
10 |
Correct |
178 ms |
26176 KB |
Output is correct |
11 |
Correct |
161 ms |
25752 KB |
Output is correct |
12 |
Correct |
192 ms |
26992 KB |
Output is correct |
13 |
Correct |
124 ms |
19688 KB |
Output is correct |
14 |
Correct |
140 ms |
22580 KB |
Output is correct |
15 |
Correct |
252 ms |
32844 KB |
Output is correct |
16 |
Correct |
259 ms |
31988 KB |
Output is correct |
17 |
Correct |
245 ms |
33404 KB |
Output is correct |
18 |
Correct |
195 ms |
25960 KB |
Output is correct |
19 |
Correct |
116 ms |
13708 KB |
Output is correct |
20 |
Correct |
309 ms |
33692 KB |
Output is correct |
21 |
Correct |
333 ms |
33136 KB |
Output is correct |
22 |
Correct |
361 ms |
34808 KB |
Output is correct |
23 |
Correct |
219 ms |
27256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
226 ms |
20032 KB |
Output is correct |
4 |
Correct |
214 ms |
20392 KB |
Output is correct |
5 |
Correct |
207 ms |
20384 KB |
Output is correct |
6 |
Correct |
232 ms |
20364 KB |
Output is correct |
7 |
Correct |
217 ms |
20472 KB |
Output is correct |
8 |
Correct |
206 ms |
19948 KB |
Output is correct |
9 |
Correct |
261 ms |
20216 KB |
Output is correct |
10 |
Correct |
213 ms |
19900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
5 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
5 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
3 ms |
5204 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
5164 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5204 KB |
Output is correct |
21 |
Correct |
4 ms |
5076 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
4 ms |
5204 KB |
Output is correct |
25 |
Correct |
4 ms |
5204 KB |
Output is correct |
26 |
Correct |
4 ms |
5204 KB |
Output is correct |
27 |
Correct |
4 ms |
5076 KB |
Output is correct |
28 |
Correct |
5 ms |
5164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5204 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
133 ms |
22524 KB |
Output is correct |
11 |
Correct |
178 ms |
26176 KB |
Output is correct |
12 |
Correct |
161 ms |
25752 KB |
Output is correct |
13 |
Correct |
192 ms |
26992 KB |
Output is correct |
14 |
Correct |
124 ms |
19688 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
5 ms |
5076 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
5 ms |
5076 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
4 ms |
5204 KB |
Output is correct |
21 |
Correct |
3 ms |
5204 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5164 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5204 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
4 ms |
5204 KB |
Output is correct |
30 |
Correct |
4 ms |
5204 KB |
Output is correct |
31 |
Correct |
4 ms |
5204 KB |
Output is correct |
32 |
Correct |
4 ms |
5076 KB |
Output is correct |
33 |
Correct |
5 ms |
5164 KB |
Output is correct |
34 |
Correct |
15 ms |
7616 KB |
Output is correct |
35 |
Correct |
166 ms |
26856 KB |
Output is correct |
36 |
Correct |
167 ms |
26644 KB |
Output is correct |
37 |
Correct |
173 ms |
26272 KB |
Output is correct |
38 |
Correct |
174 ms |
25364 KB |
Output is correct |
39 |
Correct |
168 ms |
24968 KB |
Output is correct |
40 |
Correct |
132 ms |
23020 KB |
Output is correct |
41 |
Correct |
185 ms |
27304 KB |
Output is correct |
42 |
Correct |
186 ms |
27296 KB |
Output is correct |
43 |
Correct |
104 ms |
18896 KB |
Output is correct |
44 |
Correct |
164 ms |
24716 KB |
Output is correct |
45 |
Correct |
119 ms |
19636 KB |
Output is correct |
46 |
Correct |
183 ms |
26684 KB |
Output is correct |
47 |
Correct |
153 ms |
23184 KB |
Output is correct |
48 |
Correct |
116 ms |
20384 KB |
Output is correct |
49 |
Correct |
65 ms |
11936 KB |
Output is correct |
50 |
Correct |
48 ms |
10116 KB |
Output is correct |
51 |
Correct |
92 ms |
17072 KB |
Output is correct |
52 |
Correct |
222 ms |
27964 KB |
Output is correct |
53 |
Correct |
164 ms |
24112 KB |
Output is correct |
54 |
Correct |
215 ms |
30780 KB |
Output is correct |
55 |
Correct |
123 ms |
19056 KB |
Output is correct |
56 |
Correct |
149 ms |
23012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
133 ms |
22524 KB |
Output is correct |
10 |
Correct |
178 ms |
26176 KB |
Output is correct |
11 |
Correct |
161 ms |
25752 KB |
Output is correct |
12 |
Correct |
192 ms |
26992 KB |
Output is correct |
13 |
Correct |
124 ms |
19688 KB |
Output is correct |
14 |
Correct |
140 ms |
22580 KB |
Output is correct |
15 |
Correct |
252 ms |
32844 KB |
Output is correct |
16 |
Correct |
259 ms |
31988 KB |
Output is correct |
17 |
Correct |
245 ms |
33404 KB |
Output is correct |
18 |
Correct |
195 ms |
25960 KB |
Output is correct |
19 |
Correct |
226 ms |
20032 KB |
Output is correct |
20 |
Correct |
214 ms |
20392 KB |
Output is correct |
21 |
Correct |
207 ms |
20384 KB |
Output is correct |
22 |
Correct |
232 ms |
20364 KB |
Output is correct |
23 |
Correct |
217 ms |
20472 KB |
Output is correct |
24 |
Correct |
206 ms |
19948 KB |
Output is correct |
25 |
Correct |
261 ms |
20216 KB |
Output is correct |
26 |
Correct |
213 ms |
19900 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
5 ms |
5076 KB |
Output is correct |
29 |
Correct |
3 ms |
5076 KB |
Output is correct |
30 |
Correct |
5 ms |
5076 KB |
Output is correct |
31 |
Correct |
3 ms |
5076 KB |
Output is correct |
32 |
Correct |
4 ms |
5204 KB |
Output is correct |
33 |
Correct |
3 ms |
5204 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
3 ms |
5164 KB |
Output is correct |
36 |
Correct |
15 ms |
7616 KB |
Output is correct |
37 |
Correct |
166 ms |
26856 KB |
Output is correct |
38 |
Correct |
167 ms |
26644 KB |
Output is correct |
39 |
Correct |
173 ms |
26272 KB |
Output is correct |
40 |
Correct |
174 ms |
25364 KB |
Output is correct |
41 |
Correct |
168 ms |
24968 KB |
Output is correct |
42 |
Correct |
132 ms |
23020 KB |
Output is correct |
43 |
Correct |
185 ms |
27304 KB |
Output is correct |
44 |
Correct |
186 ms |
27296 KB |
Output is correct |
45 |
Correct |
104 ms |
18896 KB |
Output is correct |
46 |
Correct |
164 ms |
24716 KB |
Output is correct |
47 |
Correct |
26 ms |
8140 KB |
Output is correct |
48 |
Correct |
399 ms |
33768 KB |
Output is correct |
49 |
Correct |
347 ms |
33168 KB |
Output is correct |
50 |
Correct |
344 ms |
32980 KB |
Output is correct |
51 |
Correct |
380 ms |
32436 KB |
Output is correct |
52 |
Correct |
322 ms |
30568 KB |
Output is correct |
53 |
Correct |
257 ms |
25232 KB |
Output is correct |
54 |
Correct |
335 ms |
34460 KB |
Output is correct |
55 |
Correct |
345 ms |
34344 KB |
Output is correct |
56 |
Correct |
247 ms |
26260 KB |
Output is correct |
57 |
Correct |
306 ms |
31952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5204 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
133 ms |
22524 KB |
Output is correct |
11 |
Correct |
178 ms |
26176 KB |
Output is correct |
12 |
Correct |
161 ms |
25752 KB |
Output is correct |
13 |
Correct |
192 ms |
26992 KB |
Output is correct |
14 |
Correct |
124 ms |
19688 KB |
Output is correct |
15 |
Correct |
140 ms |
22580 KB |
Output is correct |
16 |
Correct |
252 ms |
32844 KB |
Output is correct |
17 |
Correct |
259 ms |
31988 KB |
Output is correct |
18 |
Correct |
245 ms |
33404 KB |
Output is correct |
19 |
Correct |
195 ms |
25960 KB |
Output is correct |
20 |
Correct |
226 ms |
20032 KB |
Output is correct |
21 |
Correct |
214 ms |
20392 KB |
Output is correct |
22 |
Correct |
207 ms |
20384 KB |
Output is correct |
23 |
Correct |
232 ms |
20364 KB |
Output is correct |
24 |
Correct |
217 ms |
20472 KB |
Output is correct |
25 |
Correct |
206 ms |
19948 KB |
Output is correct |
26 |
Correct |
261 ms |
20216 KB |
Output is correct |
27 |
Correct |
213 ms |
19900 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
5 ms |
5076 KB |
Output is correct |
30 |
Correct |
3 ms |
5076 KB |
Output is correct |
31 |
Correct |
5 ms |
5076 KB |
Output is correct |
32 |
Correct |
3 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5204 KB |
Output is correct |
34 |
Correct |
3 ms |
5204 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
3 ms |
5164 KB |
Output is correct |
37 |
Correct |
15 ms |
7616 KB |
Output is correct |
38 |
Correct |
166 ms |
26856 KB |
Output is correct |
39 |
Correct |
167 ms |
26644 KB |
Output is correct |
40 |
Correct |
173 ms |
26272 KB |
Output is correct |
41 |
Correct |
174 ms |
25364 KB |
Output is correct |
42 |
Correct |
168 ms |
24968 KB |
Output is correct |
43 |
Correct |
132 ms |
23020 KB |
Output is correct |
44 |
Correct |
185 ms |
27304 KB |
Output is correct |
45 |
Correct |
186 ms |
27296 KB |
Output is correct |
46 |
Correct |
104 ms |
18896 KB |
Output is correct |
47 |
Correct |
164 ms |
24716 KB |
Output is correct |
48 |
Correct |
26 ms |
8140 KB |
Output is correct |
49 |
Correct |
399 ms |
33768 KB |
Output is correct |
50 |
Correct |
347 ms |
33168 KB |
Output is correct |
51 |
Correct |
344 ms |
32980 KB |
Output is correct |
52 |
Correct |
380 ms |
32436 KB |
Output is correct |
53 |
Correct |
322 ms |
30568 KB |
Output is correct |
54 |
Correct |
257 ms |
25232 KB |
Output is correct |
55 |
Correct |
335 ms |
34460 KB |
Output is correct |
56 |
Correct |
345 ms |
34344 KB |
Output is correct |
57 |
Correct |
247 ms |
26260 KB |
Output is correct |
58 |
Correct |
306 ms |
31952 KB |
Output is correct |
59 |
Correct |
116 ms |
13708 KB |
Output is correct |
60 |
Correct |
309 ms |
33692 KB |
Output is correct |
61 |
Correct |
333 ms |
33136 KB |
Output is correct |
62 |
Correct |
361 ms |
34808 KB |
Output is correct |
63 |
Correct |
219 ms |
27256 KB |
Output is correct |
64 |
Correct |
3 ms |
5076 KB |
Output is correct |
65 |
Correct |
3 ms |
5204 KB |
Output is correct |
66 |
Correct |
4 ms |
5076 KB |
Output is correct |
67 |
Correct |
3 ms |
5076 KB |
Output is correct |
68 |
Correct |
3 ms |
5076 KB |
Output is correct |
69 |
Correct |
4 ms |
5204 KB |
Output is correct |
70 |
Correct |
4 ms |
5204 KB |
Output is correct |
71 |
Correct |
4 ms |
5204 KB |
Output is correct |
72 |
Correct |
4 ms |
5076 KB |
Output is correct |
73 |
Correct |
5 ms |
5164 KB |
Output is correct |
74 |
Correct |
119 ms |
19636 KB |
Output is correct |
75 |
Correct |
183 ms |
26684 KB |
Output is correct |
76 |
Correct |
153 ms |
23184 KB |
Output is correct |
77 |
Correct |
116 ms |
20384 KB |
Output is correct |
78 |
Correct |
65 ms |
11936 KB |
Output is correct |
79 |
Correct |
48 ms |
10116 KB |
Output is correct |
80 |
Correct |
92 ms |
17072 KB |
Output is correct |
81 |
Correct |
222 ms |
27964 KB |
Output is correct |
82 |
Correct |
164 ms |
24112 KB |
Output is correct |
83 |
Correct |
215 ms |
30780 KB |
Output is correct |
84 |
Correct |
123 ms |
19056 KB |
Output is correct |
85 |
Correct |
149 ms |
23012 KB |
Output is correct |
86 |
Correct |
98 ms |
12536 KB |
Output is correct |
87 |
Correct |
319 ms |
32652 KB |
Output is correct |
88 |
Correct |
372 ms |
32828 KB |
Output is correct |
89 |
Correct |
241 ms |
26360 KB |
Output is correct |
90 |
Correct |
201 ms |
18576 KB |
Output is correct |
91 |
Correct |
186 ms |
18900 KB |
Output is correct |
92 |
Correct |
261 ms |
24556 KB |
Output is correct |
93 |
Correct |
366 ms |
35388 KB |
Output is correct |
94 |
Correct |
368 ms |
32736 KB |
Output is correct |
95 |
Correct |
440 ms |
39192 KB |
Output is correct |
96 |
Correct |
219 ms |
26272 KB |
Output is correct |
97 |
Correct |
325 ms |
29800 KB |
Output is correct |