#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[lg][maxn] , sz[maxn] , mark[maxn] , d[maxn] , flag , ans , dp[maxn] , mx[lg][maxn] , h[maxn] , mo[maxn];
vec<pair<int , pii>> e ;
vec<pii> adj[maxn] ;
void dfsdown(int v , int p){
for(auto u : adj[v]){
if(u.X != p ){
dfsdown(u.X , v) ;
dp[v] = min(dp[v] , max(dp[u.X] , u.Y)) ;
}
}
}
void dfsup(int v , int p){
for(auto u : adj[v]){
if(u.X != p){
dp[u.X] = min(dp[u.X] , max(u.Y , dp[v])) ;
dfsup(u.X , v) ;
}
}
}
void dfs(int v , int p){
for(auto u : adj[v]){
if(u.X != p){
par[0][u.X] = v ;
mx[0][u.X] = u.Y ;
for(int i = 1 ; i < lg; i ++ ){
par[i][u.X] = par[i-1][par[i-1][u.X]] ;
mx[i][u.X] = max(mx[i-1][u.X] , mx[i-1][par[i-1][u.X]]) ;
}
h[u.X] = h[v] + 1 ;
dfs(u.X , v) ;
}
}
}
int lca(int u , int v){
int res = 0 ;
if(h[u] > h[v]) swap(u , v) ;
for(int i = lg-1 ; i >= 0 ; i -- ){
if(par[i][v] != -1 && h[par[i][v]] >= h[u]){
res = max(res , mx[i][v]) ;
v = par[i][v] ;
}
}
if(u == v) return res ;
for(int i = lg -1 ; i >= 0 ; i -- ){
if(par[i][v] != par[i][u]){
res = max(res , mx[i][v]) ;
res = max(res , mx[i][u]) ;
u = par[i][u] ;
v = par[i][v] ;
}
}
res = max(res , mx[0][u]) ; res = max(res , mx[0][v]) ;
return res ;
}
int getMinimumFuelCapacity(int x , int y){
if(max(lca(x , y) , dp[x]) == mod)
return -1 ;
else return max(lca(x , y) , dp[x]) ;
}
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]}}) ;
adj[A[i]].pb({B[i] , W[i]}) ;
adj[B[i]].pb({A[i] , W[i]}) ;
}
sort(all(e)) ;
for(int i = 0 ; i < maxn ; i ++ ){
dp[i] = mod ;
}
for(auto u : e){
d[u.Y.X] ++ ;
d[u.Y.Y] ++ ;
if(d[u.Y.X] == 3) dp[u.Y.X] = u.X ;
if(d[u.Y.Y] == 3) dp[u.Y.Y] = u.X ;
}
for(auto u : e){
dp[u.Y.X] = min(dp[u.Y.X] , max(u.X , dp[u.Y.Y])) ;
dp[u.Y.Y] = min(dp[u.Y.Y] , max(u.X , dp[u.Y.X])) ;
}
dfsdown(0 , -1) ;
dfsup(0 , -1) ;
h[0] = 1 ;
for(int i = 0 ; i < lg ; i ++ ) par[i][0] = -1 ;
dfs(0 , -1) ;
}
/*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 |
4 ms |
5964 KB |
Output is correct |
2 |
Correct |
5 ms |
5964 KB |
Output is correct |
3 |
Correct |
4 ms |
5964 KB |
Output is correct |
4 |
Correct |
5 ms |
6092 KB |
Output is correct |
5 |
Correct |
5 ms |
6348 KB |
Output is correct |
6 |
Correct |
5 ms |
6220 KB |
Output is correct |
7 |
Correct |
5 ms |
6220 KB |
Output is correct |
8 |
Correct |
5 ms |
6220 KB |
Output is correct |
9 |
Correct |
193 ms |
28636 KB |
Output is correct |
10 |
Correct |
214 ms |
35244 KB |
Output is correct |
11 |
Correct |
219 ms |
34200 KB |
Output is correct |
12 |
Correct |
240 ms |
36104 KB |
Output is correct |
13 |
Correct |
252 ms |
38232 KB |
Output is correct |
14 |
Correct |
231 ms |
27868 KB |
Output is correct |
15 |
Correct |
699 ms |
36816 KB |
Output is correct |
16 |
Correct |
711 ms |
34212 KB |
Output is correct |
17 |
Correct |
710 ms |
39992 KB |
Output is correct |
18 |
Correct |
683 ms |
38336 KB |
Output is correct |
19 |
Runtime error |
467 ms |
524292 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5964 KB |
Output is correct |
2 |
Correct |
5 ms |
5964 KB |
Output is correct |
3 |
Correct |
303 ms |
31512 KB |
Output is correct |
4 |
Correct |
303 ms |
36456 KB |
Output is correct |
5 |
Correct |
333 ms |
36064 KB |
Output is correct |
6 |
Correct |
303 ms |
36256 KB |
Output is correct |
7 |
Correct |
325 ms |
36368 KB |
Output is correct |
8 |
Correct |
343 ms |
35200 KB |
Output is correct |
9 |
Correct |
322 ms |
35988 KB |
Output is correct |
10 |
Correct |
296 ms |
35100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5964 KB |
Output is correct |
2 |
Correct |
5 ms |
5964 KB |
Output is correct |
3 |
Correct |
4 ms |
5964 KB |
Output is correct |
4 |
Correct |
5 ms |
6092 KB |
Output is correct |
5 |
Correct |
5 ms |
6348 KB |
Output is correct |
6 |
Correct |
5 ms |
6220 KB |
Output is correct |
7 |
Correct |
5 ms |
6220 KB |
Output is correct |
8 |
Correct |
5 ms |
6220 KB |
Output is correct |
9 |
Runtime error |
253 ms |
524292 KB |
Execution killed with signal 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
253 ms |
524292 KB |
Execution killed with signal 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5964 KB |
Output is correct |
2 |
Correct |
5 ms |
5964 KB |
Output is correct |
3 |
Correct |
4 ms |
5964 KB |
Output is correct |
4 |
Correct |
5 ms |
6092 KB |
Output is correct |
5 |
Correct |
5 ms |
6348 KB |
Output is correct |
6 |
Correct |
5 ms |
6220 KB |
Output is correct |
7 |
Correct |
5 ms |
6220 KB |
Output is correct |
8 |
Correct |
5 ms |
6220 KB |
Output is correct |
9 |
Correct |
193 ms |
28636 KB |
Output is correct |
10 |
Correct |
214 ms |
35244 KB |
Output is correct |
11 |
Correct |
219 ms |
34200 KB |
Output is correct |
12 |
Correct |
240 ms |
36104 KB |
Output is correct |
13 |
Correct |
252 ms |
38232 KB |
Output is correct |
14 |
Correct |
231 ms |
27868 KB |
Output is correct |
15 |
Correct |
699 ms |
36816 KB |
Output is correct |
16 |
Correct |
711 ms |
34212 KB |
Output is correct |
17 |
Correct |
710 ms |
39992 KB |
Output is correct |
18 |
Correct |
683 ms |
38336 KB |
Output is correct |
19 |
Correct |
303 ms |
31512 KB |
Output is correct |
20 |
Correct |
303 ms |
36456 KB |
Output is correct |
21 |
Correct |
333 ms |
36064 KB |
Output is correct |
22 |
Correct |
303 ms |
36256 KB |
Output is correct |
23 |
Correct |
325 ms |
36368 KB |
Output is correct |
24 |
Correct |
343 ms |
35200 KB |
Output is correct |
25 |
Correct |
322 ms |
35988 KB |
Output is correct |
26 |
Correct |
296 ms |
35100 KB |
Output is correct |
27 |
Correct |
4 ms |
6220 KB |
Output is correct |
28 |
Correct |
5 ms |
6220 KB |
Output is correct |
29 |
Correct |
5 ms |
6220 KB |
Output is correct |
30 |
Correct |
5 ms |
6092 KB |
Output is correct |
31 |
Correct |
5 ms |
6220 KB |
Output is correct |
32 |
Correct |
5 ms |
6220 KB |
Output is correct |
33 |
Correct |
5 ms |
6220 KB |
Output is correct |
34 |
Correct |
5 ms |
6220 KB |
Output is correct |
35 |
Correct |
6 ms |
6220 KB |
Output is correct |
36 |
Correct |
18 ms |
9164 KB |
Output is correct |
37 |
Correct |
276 ms |
35552 KB |
Output is correct |
38 |
Correct |
218 ms |
32516 KB |
Output is correct |
39 |
Correct |
200 ms |
30124 KB |
Output is correct |
40 |
Correct |
195 ms |
29384 KB |
Output is correct |
41 |
Correct |
185 ms |
28836 KB |
Output is correct |
42 |
Correct |
189 ms |
27000 KB |
Output is correct |
43 |
Correct |
271 ms |
33272 KB |
Output is correct |
44 |
Correct |
230 ms |
34784 KB |
Output is correct |
45 |
Correct |
222 ms |
36240 KB |
Output is correct |
46 |
Correct |
186 ms |
29560 KB |
Output is correct |
47 |
Correct |
30 ms |
9764 KB |
Output is correct |
48 |
Correct |
740 ms |
40116 KB |
Output is correct |
49 |
Correct |
642 ms |
38124 KB |
Output is correct |
50 |
Correct |
771 ms |
36860 KB |
Output is correct |
51 |
Correct |
692 ms |
36292 KB |
Output is correct |
52 |
Correct |
598 ms |
34312 KB |
Output is correct |
53 |
Correct |
314 ms |
28900 KB |
Output is correct |
54 |
Correct |
708 ms |
39992 KB |
Output is correct |
55 |
Correct |
703 ms |
40612 KB |
Output is correct |
56 |
Correct |
669 ms |
43820 KB |
Output is correct |
57 |
Correct |
497 ms |
37212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
253 ms |
524292 KB |
Execution killed with signal 9 |