#include "swap.h"
#include <bits/stdc++.h>
#define fir first
#define sec second
#define pii pair<int, int>
#define ll long long
using namespace std;
const int mxN=100010;
const int mxM=200020;
const int INF=1000000007;
typedef struct line{
int s, e, val;
}line;
int N, M;
vector <line> lin;
vector <pii> col[mxN];
vector <int> Colp[mxN];
bool Chk[mxN];
int Pos[mxN];
int deg[mxN];
bool cmp1(line a, line b)
{
return a.val<b.val;
}
bool cmp2(pii a, pii b)
{
if(a.fir!=b.fir) return a.fir<b.fir;
return a.sec<b.sec;
}
void init(int n, int m, vector<int> U, vector<int> V, vector<int> W) {
N=n, M=m;
lin.resize(M);
for(int i=0;i<M;i++) lin[i].s=U[i], lin[i].e=V[i], lin[i].val=W[i];
sort(lin.begin(), lin.end(), cmp1);
for(int i=0;i<N;i++) col[i].push_back({0, i});
for(int i=0;i<N;i++) Colp[i].push_back(i);
for(int i=0;i<M;i++)
{
int now1=lin[i].s, now2=lin[i].e, col1, col2;
col1=col[now1].back().sec, col2=col[now2].back().sec;
if(col1==col2)
{
if(Chk[col1]) continue;
for(int ele : Colp[col1])
{
Pos[ele]=i+1;
}
Chk[col1]=true;
continue;
}
bool can;
if(Chk[col1] || Chk[col2]) can=true;
else can=false;
if(can)
{
if(!Chk[col1])
{
for(int ele : Colp[col1]) Pos[ele]=i+1;
Chk[col1]=true;
}
if(!Chk[col2])
{
for(int ele : Colp[col2]) Pos[ele]=i+1;
Chk[col2]=true;
}
}
else
{
if(deg[now1]>=2 || deg[now2]>=2)
{
for(int ele : Colp[col1]) Pos[ele]=i+1;
for(int ele : Colp[col2]) Pos[ele]=i+1;
Chk[col1]=Chk[col2]=true;
}
}
if(Colp[col1].size()<Colp[col2].size())
{
for(int ele : Colp[col1])
{
col[ele].push_back({i+1, col2});
Colp[col2].push_back(ele);
}
}
else
{
for(int ele : Colp[col2])
{
col[ele].push_back({i+1, col1});
Colp[col1].push_back(ele);
}
}
deg[now1]++;
deg[now2]++;
}
}
int getMinimumFuelCapacity(int X, int Y) {
if(col[X].back().sec!=col[Y].back().sec || Pos[X]==0 || Pos[Y]==0) return -1;
int s=0, e=M;
while(s!=e)
{
int mid=(s+e)/2;
pii tmp={mid, INF};
int tmp1=lower_bound(col[X].begin(), col[X].end(), tmp, cmp2)-col[X].begin();
int tmp2=lower_bound(col[Y].begin(), col[Y].end(), tmp, cmp2)-col[Y].begin();
tmp1--;
tmp2--;
if(col[X][tmp1].sec!=col[Y][tmp2].sec) s=mid+1;
else e=mid;
}
e=max(e, max(Pos[X], Pos[Y]));
return lin[e-1].val;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
5 ms |
5248 KB |
Output is correct |
6 |
Correct |
5 ms |
5120 KB |
Output is correct |
7 |
Correct |
5 ms |
5248 KB |
Output is correct |
8 |
Correct |
5 ms |
5120 KB |
Output is correct |
9 |
Correct |
188 ms |
22680 KB |
Output is correct |
10 |
Correct |
235 ms |
26404 KB |
Output is correct |
11 |
Correct |
229 ms |
25964 KB |
Output is correct |
12 |
Correct |
246 ms |
27248 KB |
Output is correct |
13 |
Correct |
146 ms |
19524 KB |
Output is correct |
14 |
Correct |
194 ms |
23032 KB |
Output is correct |
15 |
Correct |
336 ms |
31100 KB |
Output is correct |
16 |
Correct |
318 ms |
30244 KB |
Output is correct |
17 |
Correct |
347 ms |
31960 KB |
Output is correct |
18 |
Correct |
227 ms |
23636 KB |
Output is correct |
19 |
Correct |
184 ms |
13560 KB |
Output is correct |
20 |
Correct |
482 ms |
32364 KB |
Output is correct |
21 |
Correct |
490 ms |
32096 KB |
Output is correct |
22 |
Correct |
510 ms |
33364 KB |
Output is correct |
23 |
Correct |
345 ms |
25392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
313 ms |
22552 KB |
Output is correct |
4 |
Correct |
314 ms |
22872 KB |
Output is correct |
5 |
Correct |
324 ms |
22924 KB |
Output is correct |
6 |
Correct |
306 ms |
22748 KB |
Output is correct |
7 |
Correct |
316 ms |
23152 KB |
Output is correct |
8 |
Correct |
306 ms |
22432 KB |
Output is correct |
9 |
Correct |
312 ms |
22768 KB |
Output is correct |
10 |
Correct |
310 ms |
22448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
5 ms |
5248 KB |
Output is correct |
7 |
Correct |
5 ms |
5120 KB |
Output is correct |
8 |
Correct |
5 ms |
5248 KB |
Output is correct |
9 |
Correct |
5 ms |
5120 KB |
Output is correct |
10 |
Correct |
5 ms |
5120 KB |
Output is correct |
11 |
Correct |
6 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 |
5 ms |
5120 KB |
Output is correct |
15 |
Correct |
5 ms |
5248 KB |
Output is correct |
16 |
Correct |
5 ms |
5248 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
5 ms |
5248 KB |
Output is correct |
19 |
Correct |
4 ms |
5120 KB |
Output is correct |
20 |
Correct |
5 ms |
5248 KB |
Output is correct |
21 |
Correct |
5 ms |
5120 KB |
Output is correct |
22 |
Correct |
6 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 |
5 ms |
5120 KB |
Output is correct |
28 |
Correct |
5 ms |
5248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
5 ms |
5248 KB |
Output is correct |
7 |
Correct |
5 ms |
5120 KB |
Output is correct |
8 |
Correct |
5 ms |
5248 KB |
Output is correct |
9 |
Correct |
5 ms |
5120 KB |
Output is correct |
10 |
Correct |
188 ms |
22680 KB |
Output is correct |
11 |
Correct |
235 ms |
26404 KB |
Output is correct |
12 |
Correct |
229 ms |
25964 KB |
Output is correct |
13 |
Correct |
246 ms |
27248 KB |
Output is correct |
14 |
Correct |
146 ms |
19524 KB |
Output is correct |
15 |
Correct |
5 ms |
5120 KB |
Output is correct |
16 |
Correct |
6 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 |
5 ms |
5120 KB |
Output is correct |
20 |
Correct |
5 ms |
5248 KB |
Output is correct |
21 |
Correct |
5 ms |
5248 KB |
Output is correct |
22 |
Correct |
4 ms |
5120 KB |
Output is correct |
23 |
Correct |
5 ms |
5248 KB |
Output is correct |
24 |
Correct |
20 ms |
7680 KB |
Output is correct |
25 |
Correct |
253 ms |
27376 KB |
Output is correct |
26 |
Correct |
246 ms |
27248 KB |
Output is correct |
27 |
Correct |
240 ms |
26608 KB |
Output is correct |
28 |
Correct |
232 ms |
25840 KB |
Output is correct |
29 |
Correct |
222 ms |
25496 KB |
Output is correct |
30 |
Correct |
193 ms |
23288 KB |
Output is correct |
31 |
Correct |
252 ms |
28268 KB |
Output is correct |
32 |
Correct |
247 ms |
27760 KB |
Output is correct |
33 |
Correct |
134 ms |
19184 KB |
Output is correct |
34 |
Correct |
222 ms |
25456 KB |
Output is correct |
35 |
Correct |
4 ms |
5120 KB |
Output is correct |
36 |
Correct |
5 ms |
5248 KB |
Output is correct |
37 |
Correct |
5 ms |
5120 KB |
Output is correct |
38 |
Correct |
6 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 |
5 ms |
5120 KB |
Output is correct |
44 |
Correct |
5 ms |
5248 KB |
Output is correct |
45 |
Correct |
174 ms |
21748 KB |
Output is correct |
46 |
Correct |
238 ms |
27120 KB |
Output is correct |
47 |
Correct |
205 ms |
23792 KB |
Output is correct |
48 |
Correct |
175 ms |
21236 KB |
Output is correct |
49 |
Correct |
92 ms |
13560 KB |
Output is correct |
50 |
Correct |
77 ms |
12368 KB |
Output is correct |
51 |
Correct |
139 ms |
19060 KB |
Output is correct |
52 |
Correct |
277 ms |
30136 KB |
Output is correct |
53 |
Correct |
246 ms |
26632 KB |
Output is correct |
54 |
Correct |
311 ms |
33400 KB |
Output is correct |
55 |
Correct |
134 ms |
19392 KB |
Output is correct |
56 |
Correct |
224 ms |
25328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
5 ms |
5248 KB |
Output is correct |
6 |
Correct |
5 ms |
5120 KB |
Output is correct |
7 |
Correct |
5 ms |
5248 KB |
Output is correct |
8 |
Correct |
5 ms |
5120 KB |
Output is correct |
9 |
Correct |
188 ms |
22680 KB |
Output is correct |
10 |
Correct |
235 ms |
26404 KB |
Output is correct |
11 |
Correct |
229 ms |
25964 KB |
Output is correct |
12 |
Correct |
246 ms |
27248 KB |
Output is correct |
13 |
Correct |
146 ms |
19524 KB |
Output is correct |
14 |
Correct |
194 ms |
23032 KB |
Output is correct |
15 |
Correct |
336 ms |
31100 KB |
Output is correct |
16 |
Correct |
318 ms |
30244 KB |
Output is correct |
17 |
Correct |
347 ms |
31960 KB |
Output is correct |
18 |
Correct |
227 ms |
23636 KB |
Output is correct |
19 |
Correct |
313 ms |
22552 KB |
Output is correct |
20 |
Correct |
314 ms |
22872 KB |
Output is correct |
21 |
Correct |
324 ms |
22924 KB |
Output is correct |
22 |
Correct |
306 ms |
22748 KB |
Output is correct |
23 |
Correct |
316 ms |
23152 KB |
Output is correct |
24 |
Correct |
306 ms |
22432 KB |
Output is correct |
25 |
Correct |
312 ms |
22768 KB |
Output is correct |
26 |
Correct |
310 ms |
22448 KB |
Output is correct |
27 |
Correct |
5 ms |
5120 KB |
Output is correct |
28 |
Correct |
6 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 |
5 ms |
5120 KB |
Output is correct |
32 |
Correct |
5 ms |
5248 KB |
Output is correct |
33 |
Correct |
5 ms |
5248 KB |
Output is correct |
34 |
Correct |
4 ms |
5120 KB |
Output is correct |
35 |
Correct |
5 ms |
5248 KB |
Output is correct |
36 |
Correct |
20 ms |
7680 KB |
Output is correct |
37 |
Correct |
253 ms |
27376 KB |
Output is correct |
38 |
Correct |
246 ms |
27248 KB |
Output is correct |
39 |
Correct |
240 ms |
26608 KB |
Output is correct |
40 |
Correct |
232 ms |
25840 KB |
Output is correct |
41 |
Correct |
222 ms |
25496 KB |
Output is correct |
42 |
Correct |
193 ms |
23288 KB |
Output is correct |
43 |
Correct |
252 ms |
28268 KB |
Output is correct |
44 |
Correct |
247 ms |
27760 KB |
Output is correct |
45 |
Correct |
134 ms |
19184 KB |
Output is correct |
46 |
Correct |
222 ms |
25456 KB |
Output is correct |
47 |
Correct |
38 ms |
8148 KB |
Output is correct |
48 |
Correct |
521 ms |
32508 KB |
Output is correct |
49 |
Correct |
507 ms |
31836 KB |
Output is correct |
50 |
Correct |
494 ms |
31716 KB |
Output is correct |
51 |
Correct |
478 ms |
31204 KB |
Output is correct |
52 |
Correct |
468 ms |
29472 KB |
Output is correct |
53 |
Correct |
363 ms |
24308 KB |
Output is correct |
54 |
Correct |
510 ms |
32984 KB |
Output is correct |
55 |
Correct |
523 ms |
32996 KB |
Output is correct |
56 |
Correct |
340 ms |
24568 KB |
Output is correct |
57 |
Correct |
476 ms |
30648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
5 ms |
5248 KB |
Output is correct |
7 |
Correct |
5 ms |
5120 KB |
Output is correct |
8 |
Correct |
5 ms |
5248 KB |
Output is correct |
9 |
Correct |
5 ms |
5120 KB |
Output is correct |
10 |
Correct |
188 ms |
22680 KB |
Output is correct |
11 |
Correct |
235 ms |
26404 KB |
Output is correct |
12 |
Correct |
229 ms |
25964 KB |
Output is correct |
13 |
Correct |
246 ms |
27248 KB |
Output is correct |
14 |
Correct |
146 ms |
19524 KB |
Output is correct |
15 |
Correct |
194 ms |
23032 KB |
Output is correct |
16 |
Correct |
336 ms |
31100 KB |
Output is correct |
17 |
Correct |
318 ms |
30244 KB |
Output is correct |
18 |
Correct |
347 ms |
31960 KB |
Output is correct |
19 |
Correct |
227 ms |
23636 KB |
Output is correct |
20 |
Correct |
313 ms |
22552 KB |
Output is correct |
21 |
Correct |
314 ms |
22872 KB |
Output is correct |
22 |
Correct |
324 ms |
22924 KB |
Output is correct |
23 |
Correct |
306 ms |
22748 KB |
Output is correct |
24 |
Correct |
316 ms |
23152 KB |
Output is correct |
25 |
Correct |
306 ms |
22432 KB |
Output is correct |
26 |
Correct |
312 ms |
22768 KB |
Output is correct |
27 |
Correct |
310 ms |
22448 KB |
Output is correct |
28 |
Correct |
5 ms |
5120 KB |
Output is correct |
29 |
Correct |
6 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 |
5 ms |
5120 KB |
Output is correct |
33 |
Correct |
5 ms |
5248 KB |
Output is correct |
34 |
Correct |
5 ms |
5248 KB |
Output is correct |
35 |
Correct |
4 ms |
5120 KB |
Output is correct |
36 |
Correct |
5 ms |
5248 KB |
Output is correct |
37 |
Correct |
20 ms |
7680 KB |
Output is correct |
38 |
Correct |
253 ms |
27376 KB |
Output is correct |
39 |
Correct |
246 ms |
27248 KB |
Output is correct |
40 |
Correct |
240 ms |
26608 KB |
Output is correct |
41 |
Correct |
232 ms |
25840 KB |
Output is correct |
42 |
Correct |
222 ms |
25496 KB |
Output is correct |
43 |
Correct |
193 ms |
23288 KB |
Output is correct |
44 |
Correct |
252 ms |
28268 KB |
Output is correct |
45 |
Correct |
247 ms |
27760 KB |
Output is correct |
46 |
Correct |
134 ms |
19184 KB |
Output is correct |
47 |
Correct |
222 ms |
25456 KB |
Output is correct |
48 |
Correct |
38 ms |
8148 KB |
Output is correct |
49 |
Correct |
521 ms |
32508 KB |
Output is correct |
50 |
Correct |
507 ms |
31836 KB |
Output is correct |
51 |
Correct |
494 ms |
31716 KB |
Output is correct |
52 |
Correct |
478 ms |
31204 KB |
Output is correct |
53 |
Correct |
468 ms |
29472 KB |
Output is correct |
54 |
Correct |
363 ms |
24308 KB |
Output is correct |
55 |
Correct |
510 ms |
32984 KB |
Output is correct |
56 |
Correct |
523 ms |
32996 KB |
Output is correct |
57 |
Correct |
340 ms |
24568 KB |
Output is correct |
58 |
Correct |
476 ms |
30648 KB |
Output is correct |
59 |
Correct |
184 ms |
13560 KB |
Output is correct |
60 |
Correct |
482 ms |
32364 KB |
Output is correct |
61 |
Correct |
490 ms |
32096 KB |
Output is correct |
62 |
Correct |
510 ms |
33364 KB |
Output is correct |
63 |
Correct |
345 ms |
25392 KB |
Output is correct |
64 |
Correct |
4 ms |
5120 KB |
Output is correct |
65 |
Correct |
5 ms |
5248 KB |
Output is correct |
66 |
Correct |
5 ms |
5120 KB |
Output is correct |
67 |
Correct |
6 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 |
5 ms |
5120 KB |
Output is correct |
73 |
Correct |
5 ms |
5248 KB |
Output is correct |
74 |
Correct |
174 ms |
21748 KB |
Output is correct |
75 |
Correct |
238 ms |
27120 KB |
Output is correct |
76 |
Correct |
205 ms |
23792 KB |
Output is correct |
77 |
Correct |
175 ms |
21236 KB |
Output is correct |
78 |
Correct |
92 ms |
13560 KB |
Output is correct |
79 |
Correct |
77 ms |
12368 KB |
Output is correct |
80 |
Correct |
139 ms |
19060 KB |
Output is correct |
81 |
Correct |
277 ms |
30136 KB |
Output is correct |
82 |
Correct |
246 ms |
26632 KB |
Output is correct |
83 |
Correct |
311 ms |
33400 KB |
Output is correct |
84 |
Correct |
134 ms |
19392 KB |
Output is correct |
85 |
Correct |
224 ms |
25328 KB |
Output is correct |
86 |
Correct |
102 ms |
12204 KB |
Output is correct |
87 |
Correct |
496 ms |
31572 KB |
Output is correct |
88 |
Correct |
494 ms |
31448 KB |
Output is correct |
89 |
Correct |
391 ms |
25360 KB |
Output is correct |
90 |
Correct |
281 ms |
18004 KB |
Output is correct |
91 |
Correct |
283 ms |
18832 KB |
Output is correct |
92 |
Correct |
366 ms |
23892 KB |
Output is correct |
93 |
Correct |
520 ms |
34092 KB |
Output is correct |
94 |
Correct |
487 ms |
31444 KB |
Output is correct |
95 |
Correct |
606 ms |
37788 KB |
Output is correct |
96 |
Correct |
346 ms |
24696 KB |
Output is correct |
97 |
Correct |
428 ms |
28596 KB |
Output is correct |