#include "swap.h"
#include <vector>
#include <algorithm>
using namespace std;
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define oo 1000000001
struct edge{
int u, v;
int cost;
bool operator< (edge e) const{
return cost < e.cost;
}
};
vector<int> pr;
vector<int> sz;
vector<bool> possible;
vector<edge> ed;
vector<int> deg;
int Find(int u){
if (pr[u] == u) return u;
else return pr[u] = Find(pr[u]);
}
void Union(int u, int v){
deg[u]++; deg[v]++;
int x = Find(u);
int y = Find(v);
if (x == y){
possible[x] = true;
return;
}
if (sz[x] < sz[y]) swap(x, y);
sz[x] += sz[y];
pr[y] = x;
possible[x] = possible[y] | possible[x];
if (deg[u] >= 3 || deg[v] >= 3) possible[x] = true;
}
bool check(int x, int y){
x = Find(x);
y = Find(y);
if (x == y && possible[x]) return true;
else return false;
}
void init(int n, int m, vector<int> u, vector<int> v, vector<int> w) {
pr.resize(n);
sz.resize(n);
possible.resize(n);
ed.resize(m);
deg.resize(n);
for (int i = 0; i < m; ++i) {
ed[i].u = u[i];
ed[i].v = v[i];
ed[i].cost = w[i];
}
sort(ed.begin(), ed.end());
}
int getMinimumFuelCapacity(int x, int y) {
int n = pr.size();
int m = ed.size();
int ans = -1;
for (int i = 0; i < n; ++i) {
pr[i] = i;
sz[i] = 1;
possible[i] = false;
deg[i] = 0;
}
for (int i = 0; i < m; ++i) {
Union(ed[i].u, ed[i].v);
if (check(x, y)) {
ans = ed[i].cost;
break;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 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 |
204 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 |
46 ms |
5544 KB |
Output is correct |
10 |
Correct |
66 ms |
6768 KB |
Output is correct |
11 |
Correct |
70 ms |
6628 KB |
Output is correct |
12 |
Correct |
79 ms |
7076 KB |
Output is correct |
13 |
Correct |
72 ms |
7116 KB |
Output is correct |
14 |
Execution timed out |
2074 ms |
5928 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 |
204 KB |
Output is correct |
3 |
Execution timed out |
2092 ms |
6296 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 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 |
204 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 |
332 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 |
332 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 |
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 |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 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 |
204 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 |
204 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 |
46 ms |
5544 KB |
Output is correct |
11 |
Correct |
66 ms |
6768 KB |
Output is correct |
12 |
Correct |
70 ms |
6628 KB |
Output is correct |
13 |
Correct |
79 ms |
7076 KB |
Output is correct |
14 |
Correct |
72 ms |
7116 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 |
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 |
332 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 |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 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 |
7 ms |
1100 KB |
Output is correct |
35 |
Correct |
73 ms |
6820 KB |
Output is correct |
36 |
Correct |
72 ms |
6688 KB |
Output is correct |
37 |
Correct |
79 ms |
6828 KB |
Output is correct |
38 |
Correct |
71 ms |
6668 KB |
Output is correct |
39 |
Correct |
72 ms |
6672 KB |
Output is correct |
40 |
Correct |
65 ms |
6064 KB |
Output is correct |
41 |
Correct |
75 ms |
7064 KB |
Output is correct |
42 |
Correct |
74 ms |
6728 KB |
Output is correct |
43 |
Correct |
62 ms |
6836 KB |
Output is correct |
44 |
Correct |
78 ms |
7068 KB |
Output is correct |
45 |
Correct |
109 ms |
9580 KB |
Output is correct |
46 |
Correct |
90 ms |
6832 KB |
Output is correct |
47 |
Correct |
73 ms |
6820 KB |
Output is correct |
48 |
Correct |
72 ms |
7324 KB |
Output is correct |
49 |
Correct |
78 ms |
8520 KB |
Output is correct |
50 |
Correct |
72 ms |
6916 KB |
Output is correct |
51 |
Correct |
75 ms |
8216 KB |
Output is correct |
52 |
Correct |
104 ms |
10568 KB |
Output is correct |
53 |
Correct |
106 ms |
11452 KB |
Output is correct |
54 |
Correct |
122 ms |
12348 KB |
Output is correct |
55 |
Correct |
63 ms |
6812 KB |
Output is correct |
56 |
Correct |
120 ms |
11252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 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 |
204 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 |
46 ms |
5544 KB |
Output is correct |
10 |
Correct |
66 ms |
6768 KB |
Output is correct |
11 |
Correct |
70 ms |
6628 KB |
Output is correct |
12 |
Correct |
79 ms |
7076 KB |
Output is correct |
13 |
Correct |
72 ms |
7116 KB |
Output is correct |
14 |
Execution timed out |
2074 ms |
5928 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 |
204 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 |
204 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 |
46 ms |
5544 KB |
Output is correct |
11 |
Correct |
66 ms |
6768 KB |
Output is correct |
12 |
Correct |
70 ms |
6628 KB |
Output is correct |
13 |
Correct |
79 ms |
7076 KB |
Output is correct |
14 |
Correct |
72 ms |
7116 KB |
Output is correct |
15 |
Execution timed out |
2074 ms |
5928 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |