#include "swap.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
struct dsu{
int n;
vector<int> sz, p;
vector<bool> ok;
vector<int> adj;
dsu(int nn){
n = nn;
sz.resize(n, 1);
p.resize(n);
ok.resize(n, 0);
adj.resize(n, 0);
for(int i = 0; i < n; i++) p[i] = i;
}
int get(int x){
if(p[x] != x) p[x] = get(p[x]);
return p[x];
}
void unite(int a, int b){
adj[a]++, adj[b]++;
if(adj[a] >= 3) ok[get(a)] = 1;
if(adj[b] >= 3) ok[get(b)] = 1;
a = get(a), b = get(b);
if(a == b){
ok[a] = 1;
return;
}
if(sz[b] > sz[a]) swap(a, b);
sz[a]+=sz[b];
sz[b] = 0;
ok[a] = ok[a]|ok[b];
ok[b] = 0;
p[b] = a;
}
};
int n, m;
vector<tuple<int, int, int>> edges;
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.pb({w[i], u[i], v[i]});
}
sort(edges.begin(), edges.end());
}
int getMinimumFuelCapacity(int X, int Y){
dsu ds(n);
for(int i = 0; i < m; i++){
auto [w, a, b] = edges[i];
ds.unite(a, b);
if(ds.get(X) == ds.get(Y) && ds.ok[ds.get(X)]) return w;
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
408 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 |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 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 |
47 ms |
5640 KB |
Output is correct |
10 |
Correct |
62 ms |
6184 KB |
Output is correct |
11 |
Correct |
69 ms |
6124 KB |
Output is correct |
12 |
Correct |
72 ms |
6436 KB |
Output is correct |
13 |
Correct |
63 ms |
6332 KB |
Output is correct |
14 |
Execution timed out |
2082 ms |
5808 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
408 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
2041 ms |
9600 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
408 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 |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
308 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 |
308 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 |
308 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 |
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 |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
408 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 |
308 KB |
Output is correct |
6 |
Correct |
1 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 |
332 KB |
Output is correct |
10 |
Correct |
47 ms |
5640 KB |
Output is correct |
11 |
Correct |
62 ms |
6184 KB |
Output is correct |
12 |
Correct |
69 ms |
6124 KB |
Output is correct |
13 |
Correct |
72 ms |
6436 KB |
Output is correct |
14 |
Correct |
63 ms |
6332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
308 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 |
308 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 |
308 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 |
1 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 |
332 KB |
Output is correct |
34 |
Correct |
10 ms |
1144 KB |
Output is correct |
35 |
Correct |
68 ms |
6076 KB |
Output is correct |
36 |
Correct |
69 ms |
6076 KB |
Output is correct |
37 |
Correct |
71 ms |
6088 KB |
Output is correct |
38 |
Correct |
67 ms |
6052 KB |
Output is correct |
39 |
Correct |
68 ms |
6032 KB |
Output is correct |
40 |
Correct |
62 ms |
5672 KB |
Output is correct |
41 |
Correct |
70 ms |
6316 KB |
Output is correct |
42 |
Correct |
69 ms |
6204 KB |
Output is correct |
43 |
Correct |
56 ms |
6112 KB |
Output is correct |
44 |
Correct |
75 ms |
6332 KB |
Output is correct |
45 |
Correct |
87 ms |
10072 KB |
Output is correct |
46 |
Correct |
69 ms |
6056 KB |
Output is correct |
47 |
Correct |
69 ms |
6084 KB |
Output is correct |
48 |
Correct |
69 ms |
6572 KB |
Output is correct |
49 |
Correct |
68 ms |
9892 KB |
Output is correct |
50 |
Correct |
53 ms |
7076 KB |
Output is correct |
51 |
Correct |
73 ms |
7668 KB |
Output is correct |
52 |
Correct |
101 ms |
10608 KB |
Output is correct |
53 |
Correct |
102 ms |
11448 KB |
Output is correct |
54 |
Correct |
123 ms |
12092 KB |
Output is correct |
55 |
Correct |
60 ms |
6072 KB |
Output is correct |
56 |
Correct |
108 ms |
11068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
408 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 |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 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 |
47 ms |
5640 KB |
Output is correct |
10 |
Correct |
62 ms |
6184 KB |
Output is correct |
11 |
Correct |
69 ms |
6124 KB |
Output is correct |
12 |
Correct |
72 ms |
6436 KB |
Output is correct |
13 |
Correct |
63 ms |
6332 KB |
Output is correct |
14 |
Execution timed out |
2082 ms |
5808 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 |
408 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 |
308 KB |
Output is correct |
6 |
Correct |
1 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 |
332 KB |
Output is correct |
10 |
Correct |
47 ms |
5640 KB |
Output is correct |
11 |
Correct |
62 ms |
6184 KB |
Output is correct |
12 |
Correct |
69 ms |
6124 KB |
Output is correct |
13 |
Correct |
72 ms |
6436 KB |
Output is correct |
14 |
Correct |
63 ms |
6332 KB |
Output is correct |
15 |
Execution timed out |
2082 ms |
5808 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |