#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//#include "swap.h"
const ll maxN = 1e5+10;
const ll inf = 1e18;
ll par[maxN], timeP[maxN], cycle[maxN], sz[maxN];
ll n, m;
vector<ll> adj[maxN];
vector<pair<ll, pair<ll, ll>>> edges;
ll find(ll node, ll t) {
if(par[node]==node)return node;
if(timeP[node]<=t) {
return find(par[node], t);
}
return node;
}
void unite(ll a, ll b, ll t, bool is){
a = find(a, t);
b = find(b, t);
if(a==b){
cycle[a]=min(cycle[a], t);
cycle[b]=min(cycle[b], t);
return;
}
if(sz[a]>sz[b]) {
swap(a, b);
}
if(cycle[a]==0&&cycle[b]!=0)
cycle[a]=cycle[b];
else if(cycle[b]==0&&cycle[a]!=0)
cycle[b]=cycle[a];
if(is) {
if(cycle[a]==0)cycle[a]=t;
if(cycle[b]==0)cycle[b]=t;
}
sz[b]+=sz[a];
par[a]=b;
timeP[a]=t;
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
n=N; m=M;
for(int i = 0; i < m; i++) {
edges.push_back({W[i], {U[i], V[i]}});
}
for(int i = 0; i <= n; i++) {
par[i]=i;
sz[i]=1;
cycle[i]=inf;
}
sort(edges.begin(), edges.end());
for(auto i : edges) {
ll v = i.second.first, u = i.second.second;
ll w = i.first;
adj[v].push_back(u);
adj[u].push_back(v);
bool is = 0;
if(adj[v].size()>2||adj[u].size()>2)is=1;
unite(v, u, w, is);
}
}
int getMinimumFuelCapacity(int X, int Y) {
ll l = 0, h = 1e15;
while(l < h && l < 1e10) {
ll m = (l+h)/2;
ll v1 = find(X, m), v2 = find(Y, m);
//cout<<m<<" "<<X<<" "<<Y<<" "<<l<<" "<<h<<" "<<v1<<" "<<v2<<" "<<cycle[v1]<<" "<<cycle[v2]<<"\n";
if(v1==v2&&cycle[v1]<=m) {
h=m;
}else l = m+1;
}
if(h>1e10) {
return -1;
}else return l;
}
/*
5 6
0 0 1 1 1 2
1 2 2 3 4 3
4 4 1 2 10 3
3
1 2
2 4
0 1
3 2
0 0
1 2
5 5
1
1 2
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4724 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4812 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
33 ms |
13072 KB |
Output is correct |
10 |
Correct |
36 ms |
14716 KB |
Output is correct |
11 |
Correct |
37 ms |
15372 KB |
Output is correct |
12 |
Correct |
35 ms |
15516 KB |
Output is correct |
13 |
Correct |
34 ms |
15296 KB |
Output is correct |
14 |
Correct |
31 ms |
13980 KB |
Output is correct |
15 |
Correct |
77 ms |
19024 KB |
Output is correct |
16 |
Correct |
73 ms |
18152 KB |
Output is correct |
17 |
Correct |
80 ms |
18768 KB |
Output is correct |
18 |
Correct |
82 ms |
18664 KB |
Output is correct |
19 |
Correct |
128 ms |
10952 KB |
Output is correct |
20 |
Correct |
194 ms |
20540 KB |
Output is correct |
21 |
Correct |
221 ms |
20508 KB |
Output is correct |
22 |
Correct |
215 ms |
21148 KB |
Output is correct |
23 |
Correct |
116 ms |
21336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4724 KB |
Output is correct |
3 |
Incorrect |
70 ms |
18272 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4724 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4812 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4720 KB |
Output is correct |
10 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4720 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4724 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4812 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
33 ms |
13072 KB |
Output is correct |
11 |
Correct |
36 ms |
14716 KB |
Output is correct |
12 |
Correct |
37 ms |
15372 KB |
Output is correct |
13 |
Correct |
35 ms |
15516 KB |
Output is correct |
14 |
Correct |
34 ms |
15296 KB |
Output is correct |
15 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4724 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4812 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
33 ms |
13072 KB |
Output is correct |
10 |
Correct |
36 ms |
14716 KB |
Output is correct |
11 |
Correct |
37 ms |
15372 KB |
Output is correct |
12 |
Correct |
35 ms |
15516 KB |
Output is correct |
13 |
Correct |
34 ms |
15296 KB |
Output is correct |
14 |
Correct |
31 ms |
13980 KB |
Output is correct |
15 |
Correct |
77 ms |
19024 KB |
Output is correct |
16 |
Correct |
73 ms |
18152 KB |
Output is correct |
17 |
Correct |
80 ms |
18768 KB |
Output is correct |
18 |
Correct |
82 ms |
18664 KB |
Output is correct |
19 |
Incorrect |
70 ms |
18272 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4720 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4724 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4812 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
33 ms |
13072 KB |
Output is correct |
11 |
Correct |
36 ms |
14716 KB |
Output is correct |
12 |
Correct |
37 ms |
15372 KB |
Output is correct |
13 |
Correct |
35 ms |
15516 KB |
Output is correct |
14 |
Correct |
34 ms |
15296 KB |
Output is correct |
15 |
Correct |
31 ms |
13980 KB |
Output is correct |
16 |
Correct |
77 ms |
19024 KB |
Output is correct |
17 |
Correct |
73 ms |
18152 KB |
Output is correct |
18 |
Correct |
80 ms |
18768 KB |
Output is correct |
19 |
Correct |
82 ms |
18664 KB |
Output is correct |
20 |
Incorrect |
70 ms |
18272 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |