//Challenge: Accepted
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
struct edge{
int u, v, w;
edge(){u = v = w = 0;}
edge(int a, int b, int c){u = a, v = b, w = c;}
};
struct DSU{
int par[maxn], deg[maxn];
bool mark[maxn];
pii leaf[maxn];
void init(int n) {
for (int i = 0;i < n;i++) par[i] = i, deg[i] = 0, mark[i] = 0, leaf[i] = {i, 0};
}
int find(int a) {
return a == par[a] ? a : (par[a] = find(par[a]));
}
void Union(int a, int b) {
int pa = find(a), pb = find(b);
deg[a]++, deg[b]++;
if (deg[a] >= 3 || deg[b] >= 3 || mark[pa]) mark[pb] = 1;
if (deg[a] == 1 && deg[b] == 1) {
leaf[pb] = {a, b};
} else {
if (pa == pb && (leaf[pa] == make_pair(a, b) || leaf[pa] == make_pair(b, a))) mark[pb] = 1;
if (pa != pb) {
pii p;
if (deg[leaf[pa].ff] == 1) p.ff = leaf[pa].ff;
else p.ff = leaf[pa].ss;
if (deg[leaf[pb].ff] == 1) p.ss = leaf[pb].ff;
else p.ss = leaf[pb].ss;
leaf[pb] = p;
}
}
par[pa] = pb;
}
} d;
vector<edge> ed;
int n, m;
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++) ed.push_back(edge(U[i], V[i], W[i]));
sort(ed.begin(), ed.end(), [&] (edge x, edge y){return x.w < y.w;});
}
int getMinimumFuelCapacity(int X, int Y) {
d.init(n);
int ret = -1;
for (int i = 0;i < m;i++) {
d.Union(ed[i].u, ed[i].v);
int v = d.find(X);
debug(v, d.leaf[v].ff, d.leaf[v].ss);
if (d.find(X) == d.find(Y) && d.mark[d.find(X)]) {
ret = ed[i].w;
break;
}
}
debug();
return ret;
}
Compilation message
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:13:20: warning: statement has no effect [-Wunused-value]
13 | #define debug(...) 0
| ^
swap.cpp:71:3: note: in expansion of macro 'debug'
71 | debug(v, d.leaf[v].ff, d.leaf[v].ss);
| ^~~~~
swap.cpp:70:7: warning: unused variable 'v' [-Wunused-variable]
70 | int v = d.find(X);
| ^
swap.cpp:13:20: warning: statement has no effect [-Wunused-value]
13 | #define debug(...) 0
| ^
swap.cpp:77:2: note: in expansion of macro 'debug'
77 | debug();
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1092 KB |
Output is correct |
5 |
Correct |
1 ms |
1096 KB |
Output is correct |
6 |
Correct |
2 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
38 ms |
6220 KB |
Output is correct |
10 |
Correct |
55 ms |
6932 KB |
Output is correct |
11 |
Correct |
60 ms |
6856 KB |
Output is correct |
12 |
Correct |
60 ms |
7216 KB |
Output is correct |
13 |
Correct |
56 ms |
7232 KB |
Output is correct |
14 |
Execution timed out |
2071 ms |
6596 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Execution timed out |
2031 ms |
10180 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1092 KB |
Output is correct |
5 |
Correct |
1 ms |
1096 KB |
Output is correct |
6 |
Correct |
2 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1088 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
2 ms |
1096 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
2 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
1 ms |
1112 KB |
Output is correct |
21 |
Correct |
1 ms |
1072 KB |
Output is correct |
22 |
Correct |
2 ms |
1108 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
2 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
2 ms |
1108 KB |
Output is correct |
27 |
Correct |
1 ms |
1108 KB |
Output is correct |
28 |
Correct |
2 ms |
1232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1088 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
1092 KB |
Output is correct |
6 |
Correct |
1 ms |
1096 KB |
Output is correct |
7 |
Correct |
2 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
38 ms |
6220 KB |
Output is correct |
11 |
Correct |
55 ms |
6932 KB |
Output is correct |
12 |
Correct |
60 ms |
6856 KB |
Output is correct |
13 |
Correct |
60 ms |
7216 KB |
Output is correct |
14 |
Correct |
56 ms |
7232 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
2 ms |
1096 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
2 ms |
1108 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1112 KB |
Output is correct |
26 |
Correct |
1 ms |
1072 KB |
Output is correct |
27 |
Correct |
2 ms |
1108 KB |
Output is correct |
28 |
Correct |
1 ms |
1108 KB |
Output is correct |
29 |
Correct |
2 ms |
1108 KB |
Output is correct |
30 |
Correct |
1 ms |
1108 KB |
Output is correct |
31 |
Correct |
2 ms |
1108 KB |
Output is correct |
32 |
Correct |
1 ms |
1108 KB |
Output is correct |
33 |
Correct |
2 ms |
1232 KB |
Output is correct |
34 |
Correct |
6 ms |
2068 KB |
Output is correct |
35 |
Correct |
58 ms |
6852 KB |
Output is correct |
36 |
Correct |
58 ms |
6852 KB |
Output is correct |
37 |
Correct |
65 ms |
6848 KB |
Output is correct |
38 |
Correct |
57 ms |
6852 KB |
Output is correct |
39 |
Correct |
58 ms |
6820 KB |
Output is correct |
40 |
Correct |
56 ms |
6476 KB |
Output is correct |
41 |
Correct |
59 ms |
7096 KB |
Output is correct |
42 |
Correct |
59 ms |
6904 KB |
Output is correct |
43 |
Correct |
49 ms |
6852 KB |
Output is correct |
44 |
Correct |
65 ms |
7216 KB |
Output is correct |
45 |
Correct |
83 ms |
10840 KB |
Output is correct |
46 |
Correct |
57 ms |
6844 KB |
Output is correct |
47 |
Correct |
59 ms |
6856 KB |
Output is correct |
48 |
Correct |
64 ms |
7344 KB |
Output is correct |
49 |
Correct |
62 ms |
10684 KB |
Output is correct |
50 |
Correct |
46 ms |
7868 KB |
Output is correct |
51 |
Correct |
64 ms |
8456 KB |
Output is correct |
52 |
Correct |
86 ms |
11420 KB |
Output is correct |
53 |
Correct |
89 ms |
12244 KB |
Output is correct |
54 |
Correct |
102 ms |
12880 KB |
Output is correct |
55 |
Correct |
52 ms |
6860 KB |
Output is correct |
56 |
Correct |
100 ms |
11916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1092 KB |
Output is correct |
5 |
Correct |
1 ms |
1096 KB |
Output is correct |
6 |
Correct |
2 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
38 ms |
6220 KB |
Output is correct |
10 |
Correct |
55 ms |
6932 KB |
Output is correct |
11 |
Correct |
60 ms |
6856 KB |
Output is correct |
12 |
Correct |
60 ms |
7216 KB |
Output is correct |
13 |
Correct |
56 ms |
7232 KB |
Output is correct |
14 |
Execution timed out |
2071 ms |
6596 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1088 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
1092 KB |
Output is correct |
6 |
Correct |
1 ms |
1096 KB |
Output is correct |
7 |
Correct |
2 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
38 ms |
6220 KB |
Output is correct |
11 |
Correct |
55 ms |
6932 KB |
Output is correct |
12 |
Correct |
60 ms |
6856 KB |
Output is correct |
13 |
Correct |
60 ms |
7216 KB |
Output is correct |
14 |
Correct |
56 ms |
7232 KB |
Output is correct |
15 |
Execution timed out |
2071 ms |
6596 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |