#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<tuple<int, int, int>> edge;
vector<int> link;
vector<int> volume;
vector<bool> swapable;
vector<int> degree;
int find(int x) {
if (x == link[x]) return x;
return link[x] = find(link[x]);
}
bool same(int a, int b) {
return find(a) == find(b);
}
void unite(int a, int b) {
a = find(a); b = find(b);
if (volume[a] < volume[b]) swap(a, b);
volume[a] += volume[b];
swapable[a] = swapable[a] || swapable[b];
link[b] = a;
}
bool cmp(tuple<int, int, int>& tul1, tuple<int, int, int>& tul2)
{
return (get<2>(tul1) < get<2>(tul2));
}
void init(int n1, int m1, vector<int> v, vector<int> u, vector<int> w) {
n = n1;
m = m1;
for (int i=0; i<m; i++)
{
edge.push_back({v[i], u[i], w[i]});
}
sort(edge.begin(), edge.end(), cmp);
link.resize(n, 0);
volume.resize(n, 0);
swapable.resize(n, 0);
degree.resize(n, 0);
}
int getMinimumFuelCapacity(int x, int y) {
for (int i=0; i<n; i++)
{
link[i]=i;
volume[i]=1;
swapable[i]=0;
degree[i]=0;
}
for (int i=0; i<n; i++) {
link[i] = i;
volume[i] = 1;
}
for (auto e: edge)
{
int u = get<0>(e);
int v = get<1>(e);
int w = get<2>(e);
degree[u]++; degree[v]++;
if (same(u, v) || degree[u] >= 3 || degree[v] >= 3)
{
swapable[find(u)] = true;
swapable[find(v)] = true;
}
unite(u, v);
if (same(x, y) && swapable[find(x)]) {return w;}
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
30 ms |
4120 KB |
Output is correct |
10 |
Correct |
43 ms |
4728 KB |
Output is correct |
11 |
Correct |
46 ms |
4804 KB |
Output is correct |
12 |
Correct |
49 ms |
5068 KB |
Output is correct |
13 |
Correct |
45 ms |
5312 KB |
Output is correct |
14 |
Execution timed out |
2077 ms |
4048 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Execution timed out |
2063 ms |
6212 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
30 ms |
4120 KB |
Output is correct |
11 |
Correct |
43 ms |
4728 KB |
Output is correct |
12 |
Correct |
46 ms |
4804 KB |
Output is correct |
13 |
Correct |
49 ms |
5068 KB |
Output is correct |
14 |
Correct |
45 ms |
5312 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
5 ms |
1048 KB |
Output is correct |
35 |
Correct |
48 ms |
5120 KB |
Output is correct |
36 |
Correct |
47 ms |
5064 KB |
Output is correct |
37 |
Correct |
52 ms |
5068 KB |
Output is correct |
38 |
Correct |
58 ms |
5060 KB |
Output is correct |
39 |
Correct |
47 ms |
5072 KB |
Output is correct |
40 |
Correct |
44 ms |
4424 KB |
Output is correct |
41 |
Correct |
48 ms |
5072 KB |
Output is correct |
42 |
Correct |
48 ms |
5060 KB |
Output is correct |
43 |
Correct |
40 ms |
5068 KB |
Output is correct |
44 |
Correct |
51 ms |
5068 KB |
Output is correct |
45 |
Correct |
64 ms |
6856 KB |
Output is correct |
46 |
Correct |
48 ms |
6852 KB |
Output is correct |
47 |
Correct |
49 ms |
6856 KB |
Output is correct |
48 |
Correct |
51 ms |
7364 KB |
Output is correct |
49 |
Correct |
51 ms |
9924 KB |
Output is correct |
50 |
Correct |
42 ms |
7204 KB |
Output is correct |
51 |
Correct |
61 ms |
8192 KB |
Output is correct |
52 |
Correct |
70 ms |
11972 KB |
Output is correct |
53 |
Correct |
77 ms |
11512 KB |
Output is correct |
54 |
Correct |
81 ms |
13504 KB |
Output is correct |
55 |
Correct |
42 ms |
6860 KB |
Output is correct |
56 |
Correct |
81 ms |
11256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
30 ms |
4120 KB |
Output is correct |
10 |
Correct |
43 ms |
4728 KB |
Output is correct |
11 |
Correct |
46 ms |
4804 KB |
Output is correct |
12 |
Correct |
49 ms |
5068 KB |
Output is correct |
13 |
Correct |
45 ms |
5312 KB |
Output is correct |
14 |
Execution timed out |
2077 ms |
4048 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
30 ms |
4120 KB |
Output is correct |
11 |
Correct |
43 ms |
4728 KB |
Output is correct |
12 |
Correct |
46 ms |
4804 KB |
Output is correct |
13 |
Correct |
49 ms |
5068 KB |
Output is correct |
14 |
Correct |
45 ms |
5312 KB |
Output is correct |
15 |
Execution timed out |
2077 ms |
4048 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |