#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define pll pair<ll , ll >
#define all(x) (x).begin(),(x).end()
#define SZ(x) (ll)(x).size()
#define X first
#define Y second
#define mp make_pair
#define pii pair<int , int>
#define vec vector
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
// BIG p : 1000000000000037 , 100000000003
ll poww(ll a, ll b, ll md) {
return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
const int maxn = 2000*100+5 ;
const ll inf = 9223372036854775807 ;
const ll mod = 1e9 + 7 ;
const int lg = 20 ;
int par[maxn] , sz[maxn] , mark[maxn] , d[maxn] , flag , ans ;
vec<pair<int , pii>> e ;
void prep(){
for(int i = 0 ; i < maxn ; i ++ ){
par[i] = i ;
sz[i] = 1 ;
mark[i] = d[i] = 0 ;
}
}
int getpar(int v){
return v == par[v] ? v : par[v] = getpar(par[v]) ;
}
void merge(int x , int y){
d[x] ++ , d[y] ++ ;
flag = 0 ; if(d[x] >= 3 || d[y] >= 3) flag = 1 ;
x = getpar(x) , y = getpar(y) ;
if(x == y){
mark[x] = 1 ;
return ;
}
if(sz[x] < sz[y]) swap(x , y) ;
par[y] = x ;
sz[x] += sz[y] ;
mark[x] |= (flag | mark[y] ) ;
}
int getMinimumFuelCapacity(int x , int y){
prep() ;
for(auto u : e){
merge(u.Y.X , u.Y.Y) ;
ans = u.X ;
if(getpar(x) == getpar(y) && mark[getpar(x)]){
return ans ;
}
}
return -1 ;
}
void init(int n , int m , vec<int> A , vec<int> B , vec<int> W ){
for(int i = 0 ; i < m ; i ++ ){
e.pb({W[i] , {A[i] , B[i]}}) ;
}
sort(all(e)) ;
}
/*int main()
{
migmig ;
int n , m ;
cin>>n>>m ;
int u[m] , v[m] , w[m] ;
for(int i = 0 ; i < m ; i ++ ) cin>>u[i]>>v[i]>>w[i] ;
init(n , m , u , v , w) ;
int q ;
cin>>q ;
while(q--){
int U , V ;
cin>>U>>V ;
cout<<getMinimumFuelCapacity(U , V) << endl ;
}
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
3 ms |
3404 KB |
Output is correct |
3 |
Correct |
3 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3408 KB |
Output is correct |
5 |
Correct |
3 ms |
3404 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
3 ms |
3404 KB |
Output is correct |
8 |
Correct |
4 ms |
3404 KB |
Output is correct |
9 |
Correct |
45 ms |
5412 KB |
Output is correct |
10 |
Correct |
61 ms |
5716 KB |
Output is correct |
11 |
Correct |
65 ms |
5740 KB |
Output is correct |
12 |
Correct |
68 ms |
5796 KB |
Output is correct |
13 |
Correct |
60 ms |
5796 KB |
Output is correct |
14 |
Execution timed out |
2064 ms |
5544 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
3 ms |
3404 KB |
Output is correct |
3 |
Execution timed out |
2075 ms |
7840 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
3 ms |
3404 KB |
Output is correct |
3 |
Correct |
3 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3408 KB |
Output is correct |
5 |
Correct |
3 ms |
3404 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
3 ms |
3404 KB |
Output is correct |
8 |
Correct |
4 ms |
3404 KB |
Output is correct |
9 |
Correct |
2 ms |
3404 KB |
Output is correct |
10 |
Correct |
3 ms |
3404 KB |
Output is correct |
11 |
Correct |
3 ms |
3404 KB |
Output is correct |
12 |
Correct |
4 ms |
3404 KB |
Output is correct |
13 |
Correct |
3 ms |
3404 KB |
Output is correct |
14 |
Correct |
3 ms |
3404 KB |
Output is correct |
15 |
Correct |
3 ms |
3404 KB |
Output is correct |
16 |
Correct |
3 ms |
3404 KB |
Output is correct |
17 |
Correct |
3 ms |
3404 KB |
Output is correct |
18 |
Correct |
3 ms |
3408 KB |
Output is correct |
19 |
Correct |
3 ms |
3404 KB |
Output is correct |
20 |
Correct |
3 ms |
3404 KB |
Output is correct |
21 |
Correct |
3 ms |
3404 KB |
Output is correct |
22 |
Correct |
3 ms |
3532 KB |
Output is correct |
23 |
Correct |
3 ms |
3404 KB |
Output is correct |
24 |
Correct |
4 ms |
3532 KB |
Output is correct |
25 |
Correct |
4 ms |
3532 KB |
Output is correct |
26 |
Correct |
4 ms |
3532 KB |
Output is correct |
27 |
Correct |
3 ms |
3404 KB |
Output is correct |
28 |
Correct |
4 ms |
3532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
2 ms |
3404 KB |
Output is correct |
3 |
Correct |
3 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
3 ms |
3404 KB |
Output is correct |
8 |
Correct |
3 ms |
3404 KB |
Output is correct |
9 |
Correct |
4 ms |
3404 KB |
Output is correct |
10 |
Correct |
45 ms |
5412 KB |
Output is correct |
11 |
Correct |
61 ms |
5716 KB |
Output is correct |
12 |
Correct |
65 ms |
5740 KB |
Output is correct |
13 |
Correct |
68 ms |
5796 KB |
Output is correct |
14 |
Correct |
60 ms |
5796 KB |
Output is correct |
15 |
Correct |
3 ms |
3404 KB |
Output is correct |
16 |
Correct |
3 ms |
3404 KB |
Output is correct |
17 |
Correct |
4 ms |
3404 KB |
Output is correct |
18 |
Correct |
3 ms |
3404 KB |
Output is correct |
19 |
Correct |
3 ms |
3404 KB |
Output is correct |
20 |
Correct |
3 ms |
3404 KB |
Output is correct |
21 |
Correct |
3 ms |
3404 KB |
Output is correct |
22 |
Correct |
3 ms |
3404 KB |
Output is correct |
23 |
Correct |
3 ms |
3408 KB |
Output is correct |
24 |
Correct |
3 ms |
3404 KB |
Output is correct |
25 |
Correct |
3 ms |
3404 KB |
Output is correct |
26 |
Correct |
3 ms |
3404 KB |
Output is correct |
27 |
Correct |
3 ms |
3532 KB |
Output is correct |
28 |
Correct |
3 ms |
3404 KB |
Output is correct |
29 |
Correct |
4 ms |
3532 KB |
Output is correct |
30 |
Correct |
4 ms |
3532 KB |
Output is correct |
31 |
Correct |
4 ms |
3532 KB |
Output is correct |
32 |
Correct |
3 ms |
3404 KB |
Output is correct |
33 |
Correct |
4 ms |
3532 KB |
Output is correct |
34 |
Correct |
9 ms |
4236 KB |
Output is correct |
35 |
Correct |
77 ms |
7752 KB |
Output is correct |
36 |
Correct |
74 ms |
7700 KB |
Output is correct |
37 |
Correct |
66 ms |
7708 KB |
Output is correct |
38 |
Correct |
66 ms |
7632 KB |
Output is correct |
39 |
Correct |
73 ms |
7608 KB |
Output is correct |
40 |
Correct |
60 ms |
7288 KB |
Output is correct |
41 |
Correct |
71 ms |
7948 KB |
Output is correct |
42 |
Correct |
68 ms |
7712 KB |
Output is correct |
43 |
Correct |
55 ms |
7696 KB |
Output is correct |
44 |
Correct |
71 ms |
7916 KB |
Output is correct |
45 |
Correct |
89 ms |
10064 KB |
Output is correct |
46 |
Correct |
67 ms |
7692 KB |
Output is correct |
47 |
Correct |
78 ms |
7716 KB |
Output is correct |
48 |
Correct |
67 ms |
8092 KB |
Output is correct |
49 |
Correct |
73 ms |
9972 KB |
Output is correct |
50 |
Correct |
58 ms |
8624 KB |
Output is correct |
51 |
Correct |
74 ms |
9244 KB |
Output is correct |
52 |
Correct |
100 ms |
10700 KB |
Output is correct |
53 |
Correct |
100 ms |
11520 KB |
Output is correct |
54 |
Correct |
117 ms |
12172 KB |
Output is correct |
55 |
Correct |
56 ms |
7696 KB |
Output is correct |
56 |
Correct |
109 ms |
11256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
3 ms |
3404 KB |
Output is correct |
3 |
Correct |
3 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3408 KB |
Output is correct |
5 |
Correct |
3 ms |
3404 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
3 ms |
3404 KB |
Output is correct |
8 |
Correct |
4 ms |
3404 KB |
Output is correct |
9 |
Correct |
45 ms |
5412 KB |
Output is correct |
10 |
Correct |
61 ms |
5716 KB |
Output is correct |
11 |
Correct |
65 ms |
5740 KB |
Output is correct |
12 |
Correct |
68 ms |
5796 KB |
Output is correct |
13 |
Correct |
60 ms |
5796 KB |
Output is correct |
14 |
Execution timed out |
2064 ms |
5544 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
2 ms |
3404 KB |
Output is correct |
3 |
Correct |
3 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
3 ms |
3404 KB |
Output is correct |
8 |
Correct |
3 ms |
3404 KB |
Output is correct |
9 |
Correct |
4 ms |
3404 KB |
Output is correct |
10 |
Correct |
45 ms |
5412 KB |
Output is correct |
11 |
Correct |
61 ms |
5716 KB |
Output is correct |
12 |
Correct |
65 ms |
5740 KB |
Output is correct |
13 |
Correct |
68 ms |
5796 KB |
Output is correct |
14 |
Correct |
60 ms |
5796 KB |
Output is correct |
15 |
Execution timed out |
2064 ms |
5544 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |