#include "swap.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define mk make_pair
int i,n,m,b[300000],t[300000],sz[300000],a[300000],x,y;
pair<int , pair<int , int>> p[300000];
void init(int N, int M, vector <int> U, vector <int> V, vector <int> W) {
n = N;
m = M;
for (i=0 ; i<m ; i++){
p[i].first=W[i];
p[i].second.first=U[i];
p[i].second.second=V[i];
}
sort (p,p+m);
}
int fnd(int xx){
if(xx==t[xx]){
return xx;
}
else return t[xx]=fnd(t[xx]);
}
void negtge( int x , int y){
x=fnd(x);
y=fnd(y);
if(sz[x] < sz[y]){
swap(x,y);
}
sz[x]+=sz[y];
if(b[y]==1){
b[x]=1;
}
t[y]=x;
}
int getMinimumFuelCapacity(int u, int v){
for(i=0 ; i<n ; i++){
t[i]=i;
sz[i]=1;
b[i]=0;
a[i]=0;
}
for(i=0 ; i<m ; i++){
x=p[i].second.first;
y=p[i].second.second;
a[x]++;
a[y]++;
if(fnd(x)==fnd(y) || a[x]>2 || a[y]>2){
b[fnd(x)]=1;
b[fnd(y)]=1;
}
negtge(x,y);
if(fnd(u)==fnd(v) && b[fnd(u)]==1){
return p[i].first;
}
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
42 ms |
3372 KB |
Output is correct |
10 |
Correct |
61 ms |
4008 KB |
Output is correct |
11 |
Correct |
65 ms |
4016 KB |
Output is correct |
12 |
Correct |
68 ms |
4148 KB |
Output is correct |
13 |
Correct |
69 ms |
4104 KB |
Output is correct |
14 |
Execution timed out |
2074 ms |
3496 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
2088 ms |
6192 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
42 ms |
3372 KB |
Output is correct |
11 |
Correct |
61 ms |
4008 KB |
Output is correct |
12 |
Correct |
65 ms |
4016 KB |
Output is correct |
13 |
Correct |
68 ms |
4148 KB |
Output is correct |
14 |
Correct |
69 ms |
4104 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
400 KB |
Output is correct |
34 |
Correct |
7 ms |
940 KB |
Output is correct |
35 |
Correct |
65 ms |
4144 KB |
Output is correct |
36 |
Correct |
68 ms |
4220 KB |
Output is correct |
37 |
Correct |
67 ms |
4148 KB |
Output is correct |
38 |
Correct |
65 ms |
4156 KB |
Output is correct |
39 |
Correct |
66 ms |
4140 KB |
Output is correct |
40 |
Correct |
60 ms |
3752 KB |
Output is correct |
41 |
Correct |
84 ms |
4152 KB |
Output is correct |
42 |
Correct |
82 ms |
4136 KB |
Output is correct |
43 |
Correct |
53 ms |
4144 KB |
Output is correct |
44 |
Correct |
75 ms |
4148 KB |
Output is correct |
45 |
Correct |
92 ms |
5364 KB |
Output is correct |
46 |
Correct |
68 ms |
4184 KB |
Output is correct |
47 |
Correct |
71 ms |
4316 KB |
Output is correct |
48 |
Correct |
80 ms |
4456 KB |
Output is correct |
49 |
Correct |
65 ms |
5828 KB |
Output is correct |
50 |
Correct |
54 ms |
4544 KB |
Output is correct |
51 |
Correct |
73 ms |
4804 KB |
Output is correct |
52 |
Correct |
97 ms |
5904 KB |
Output is correct |
53 |
Correct |
106 ms |
6488 KB |
Output is correct |
54 |
Correct |
113 ms |
7296 KB |
Output is correct |
55 |
Correct |
72 ms |
4148 KB |
Output is correct |
56 |
Correct |
119 ms |
6348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
42 ms |
3372 KB |
Output is correct |
10 |
Correct |
61 ms |
4008 KB |
Output is correct |
11 |
Correct |
65 ms |
4016 KB |
Output is correct |
12 |
Correct |
68 ms |
4148 KB |
Output is correct |
13 |
Correct |
69 ms |
4104 KB |
Output is correct |
14 |
Execution timed out |
2074 ms |
3496 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
42 ms |
3372 KB |
Output is correct |
11 |
Correct |
61 ms |
4008 KB |
Output is correct |
12 |
Correct |
65 ms |
4016 KB |
Output is correct |
13 |
Correct |
68 ms |
4148 KB |
Output is correct |
14 |
Correct |
69 ms |
4104 KB |
Output is correct |
15 |
Execution timed out |
2074 ms |
3496 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |