#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define SZ(a) (int)a.size()
using ll = long long;
const int maxn = (int)1e5+10;
const int INF = (ll)1e9;
vector<pair<int,int>> adj[maxn];
ll dis[maxn]; int tot = 0;
int par[maxn];
bool vis[maxn];
int n, m, p[maxn], sz[maxn];
int findSet(int i){ return p[i]==i?i:p[i]=findSet(p[i]); }
bool isSameSet(int i, int j) { return findSet(i)==findSet(j); }
bool unionSet(int i, int j){
int x = findSet(i), y = findSet(j);
if(x==y) return false;
if(sz[x] < sz[y]) swap(x,y);
p[y]=x, sz[x]+=sz[y];
return true;
}
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++){
adj[u[i]].pb({v[i],w[i]});
adj[v[i]].pb({u[i],w[i]});
}
}
bool chk(int w, int x, int y){
int mx_deg = 0, cnt = 0;
for(int i = 0; i < n; i++) p[i] = i, sz[i] = 1;
for(int i = 0; i < n; i++)
for(auto u : adj[i])
if(u.se<=w) unionSet(i,u.fi);
if(!isSameSet(x,y)) return 0;
bool ok = true;
for(int i = 0; i < n; i++){
if(!isSameSet(i,x)) continue;
int deg = 0;
for(auto u : adj[i])
if(u.se<=w) deg++;
if(mx_deg<deg) mx_deg=deg,cnt=1;
else if(mx_deg==deg) cnt++;
if(deg==1) ok=0;
}
if(mx_deg>=3) return 1;
if(mx_deg<=1) return 0;
return ok;
}
/*
5 6
0 1 4
0 2 4
1 2 1
1 3 2
1 4 10
2 3 3
3
1 2
2 4
0 1
*/
int getMinimumFuelCapacity(int x, int y) {
int l = 1, r = INF+1;
while(l<r){
int mid = (l+r)/2;
if(chk(mid,x,y)) r=mid;
else l=mid+1;
}
return (l==INF+1?-1:l);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
5 ms |
2664 KB |
Output is correct |
5 |
Correct |
5 ms |
2676 KB |
Output is correct |
6 |
Correct |
5 ms |
2644 KB |
Output is correct |
7 |
Correct |
7 ms |
2644 KB |
Output is correct |
8 |
Correct |
7 ms |
2684 KB |
Output is correct |
9 |
Correct |
261 ms |
8296 KB |
Output is correct |
10 |
Correct |
751 ms |
9236 KB |
Output is correct |
11 |
Correct |
932 ms |
9188 KB |
Output is correct |
12 |
Correct |
951 ms |
9548 KB |
Output is correct |
13 |
Correct |
1121 ms |
9500 KB |
Output is correct |
14 |
Execution timed out |
2054 ms |
8396 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Execution timed out |
2043 ms |
11508 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
5 ms |
2664 KB |
Output is correct |
5 |
Correct |
5 ms |
2676 KB |
Output is correct |
6 |
Correct |
5 ms |
2644 KB |
Output is correct |
7 |
Correct |
7 ms |
2644 KB |
Output is correct |
8 |
Correct |
7 ms |
2684 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
6 ms |
2644 KB |
Output is correct |
11 |
Correct |
6 ms |
2672 KB |
Output is correct |
12 |
Correct |
6 ms |
2672 KB |
Output is correct |
13 |
Correct |
6 ms |
2724 KB |
Output is correct |
14 |
Correct |
6 ms |
2644 KB |
Output is correct |
15 |
Correct |
7 ms |
2668 KB |
Output is correct |
16 |
Correct |
6 ms |
2644 KB |
Output is correct |
17 |
Correct |
6 ms |
2644 KB |
Output is correct |
18 |
Correct |
7 ms |
2744 KB |
Output is correct |
19 |
Correct |
6 ms |
2672 KB |
Output is correct |
20 |
Correct |
7 ms |
2744 KB |
Output is correct |
21 |
Correct |
7 ms |
2676 KB |
Output is correct |
22 |
Correct |
5 ms |
2804 KB |
Output is correct |
23 |
Correct |
6 ms |
2772 KB |
Output is correct |
24 |
Correct |
8 ms |
2808 KB |
Output is correct |
25 |
Correct |
8 ms |
2772 KB |
Output is correct |
26 |
Correct |
10 ms |
2772 KB |
Output is correct |
27 |
Correct |
6 ms |
2644 KB |
Output is correct |
28 |
Correct |
9 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
5 ms |
2664 KB |
Output is correct |
6 |
Correct |
5 ms |
2676 KB |
Output is correct |
7 |
Correct |
5 ms |
2644 KB |
Output is correct |
8 |
Correct |
7 ms |
2644 KB |
Output is correct |
9 |
Correct |
7 ms |
2684 KB |
Output is correct |
10 |
Correct |
261 ms |
8296 KB |
Output is correct |
11 |
Correct |
751 ms |
9236 KB |
Output is correct |
12 |
Correct |
932 ms |
9188 KB |
Output is correct |
13 |
Correct |
951 ms |
9548 KB |
Output is correct |
14 |
Correct |
1121 ms |
9500 KB |
Output is correct |
15 |
Correct |
6 ms |
2644 KB |
Output is correct |
16 |
Correct |
6 ms |
2672 KB |
Output is correct |
17 |
Correct |
6 ms |
2672 KB |
Output is correct |
18 |
Correct |
6 ms |
2724 KB |
Output is correct |
19 |
Correct |
6 ms |
2644 KB |
Output is correct |
20 |
Correct |
7 ms |
2668 KB |
Output is correct |
21 |
Correct |
6 ms |
2644 KB |
Output is correct |
22 |
Correct |
6 ms |
2644 KB |
Output is correct |
23 |
Correct |
7 ms |
2744 KB |
Output is correct |
24 |
Correct |
6 ms |
2672 KB |
Output is correct |
25 |
Correct |
7 ms |
2744 KB |
Output is correct |
26 |
Correct |
7 ms |
2676 KB |
Output is correct |
27 |
Correct |
5 ms |
2804 KB |
Output is correct |
28 |
Correct |
6 ms |
2772 KB |
Output is correct |
29 |
Correct |
8 ms |
2808 KB |
Output is correct |
30 |
Correct |
8 ms |
2772 KB |
Output is correct |
31 |
Correct |
10 ms |
2772 KB |
Output is correct |
32 |
Correct |
6 ms |
2644 KB |
Output is correct |
33 |
Correct |
9 ms |
2772 KB |
Output is correct |
34 |
Correct |
27 ms |
3852 KB |
Output is correct |
35 |
Correct |
1002 ms |
9960 KB |
Output is correct |
36 |
Correct |
947 ms |
9960 KB |
Output is correct |
37 |
Correct |
1059 ms |
9932 KB |
Output is correct |
38 |
Correct |
1039 ms |
9860 KB |
Output is correct |
39 |
Correct |
931 ms |
9804 KB |
Output is correct |
40 |
Correct |
927 ms |
9332 KB |
Output is correct |
41 |
Correct |
1033 ms |
10156 KB |
Output is correct |
42 |
Correct |
1086 ms |
9860 KB |
Output is correct |
43 |
Correct |
840 ms |
10060 KB |
Output is correct |
44 |
Correct |
1032 ms |
10720 KB |
Output is correct |
45 |
Correct |
1020 ms |
13860 KB |
Output is correct |
46 |
Correct |
1043 ms |
9832 KB |
Output is correct |
47 |
Correct |
1072 ms |
9864 KB |
Output is correct |
48 |
Correct |
996 ms |
10700 KB |
Output is correct |
49 |
Correct |
139 ms |
14028 KB |
Output is correct |
50 |
Correct |
165 ms |
11084 KB |
Output is correct |
51 |
Correct |
735 ms |
12308 KB |
Output is correct |
52 |
Correct |
1529 ms |
15052 KB |
Output is correct |
53 |
Correct |
1209 ms |
16256 KB |
Output is correct |
54 |
Correct |
1929 ms |
17424 KB |
Output is correct |
55 |
Correct |
950 ms |
9852 KB |
Output is correct |
56 |
Correct |
1505 ms |
15840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
5 ms |
2664 KB |
Output is correct |
5 |
Correct |
5 ms |
2676 KB |
Output is correct |
6 |
Correct |
5 ms |
2644 KB |
Output is correct |
7 |
Correct |
7 ms |
2644 KB |
Output is correct |
8 |
Correct |
7 ms |
2684 KB |
Output is correct |
9 |
Correct |
261 ms |
8296 KB |
Output is correct |
10 |
Correct |
751 ms |
9236 KB |
Output is correct |
11 |
Correct |
932 ms |
9188 KB |
Output is correct |
12 |
Correct |
951 ms |
9548 KB |
Output is correct |
13 |
Correct |
1121 ms |
9500 KB |
Output is correct |
14 |
Execution timed out |
2054 ms |
8396 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
5 ms |
2664 KB |
Output is correct |
6 |
Correct |
5 ms |
2676 KB |
Output is correct |
7 |
Correct |
5 ms |
2644 KB |
Output is correct |
8 |
Correct |
7 ms |
2644 KB |
Output is correct |
9 |
Correct |
7 ms |
2684 KB |
Output is correct |
10 |
Correct |
261 ms |
8296 KB |
Output is correct |
11 |
Correct |
751 ms |
9236 KB |
Output is correct |
12 |
Correct |
932 ms |
9188 KB |
Output is correct |
13 |
Correct |
951 ms |
9548 KB |
Output is correct |
14 |
Correct |
1121 ms |
9500 KB |
Output is correct |
15 |
Execution timed out |
2054 ms |
8396 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |