#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct UFDS {
int parent;
bool line;
pair<int, int> endpoints;
} Data[N];
vector<pair<pair<int, int>, int> > edge;
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
return a.second < b.second;
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
for(int i = 0; i < N; i++) {
Data[i].parent = i;
Data[i].line = true;
Data[i].endpoints = {i, i};
}
for(int i = 0; i < M; i++) {
edge.push_back(make_pair(make_pair(U[i], V[i]), W[i]));
}
sort(edge.begin(), edge.end(), cmp);
}
int Find(int x) {
if(Data[x].parent == x)
return x;
return Data[x].parent = Find(Data[x].parent);
}
void Unite(int a, int b) {
int parA = Find(a), parB = Find(b);
if(parA == parB) {
Data[parA].line = false;
Data[parA].endpoints = {-1, -1};
}
else {
Data[parB].parent = parA;
if(!Data[parB].line || !Data[parA].line) {
Data[parA].line = false;
Data[parA].endpoints = {-1, -1};
}
else {
if(Data[parA].endpoints.first != a) {
swap(Data[parA].endpoints.first, Data[parA].endpoints.second);
}
if(Data[parB].endpoints.first != b) {
swap(Data[parB].endpoints.first, Data[parB].endpoints.second);
}
if(a != Data[parA].endpoints.first || b != Data[parB].endpoints.first) {
Data[parA].line = false;
Data[parA].endpoints = {-1, -1};
}
else {
Data[parA].endpoints.first = Data[parB].endpoints.second;
}
}
}
}
void Ini() {
for(int i = 0; i < N; i++) {
Data[i].parent = i;
Data[i].line = true;
Data[i].endpoints = {i, i};
}
}
int getMinimumFuelCapacity(int X, int Y) {
Ini();
//cout << "X = " << X << ", Y = " << Y << "\n";
for(int i = 0; i < edge.size(); i++) {
if(Find(edge[i].first.first) != Find(edge[i].first.second)) {
//cout << "Uniting because of diff components: " << edge[i].first.first << ", " << edge[i].first.second << "\n";
Unite(edge[i].first.first, edge[i].first.second);
}
else if(Data[edge[i].first.first].line) {
//cout << "Uniting because its a line: " << edge[i].first.first << ", " << edge[i].first.second << "\n";
Unite(edge[i].first.first, edge[i].first.second);
}
//else {
//cout << "Not uniting: " << edge[i].first.first << ", " << edge[i].first.second << "\n";
//}
//cout << "Components: " << Find(X) << " " << Find(Y) << "\n";
//cout << "Is it a line? : " << Data[X].line << "\n";
if(Find(X) == Find(Y) && !Data[Find(X)].line) {
return edge[i].second;
}
}
return -1;
}
Compilation message
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:78:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i = 0; i < edge.size(); i++) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1740 KB |
Output is correct |
2 |
Correct |
3 ms |
1740 KB |
Output is correct |
3 |
Correct |
2 ms |
1740 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
4 ms |
1868 KB |
Output is correct |
6 |
Correct |
3 ms |
1900 KB |
Output is correct |
7 |
Correct |
3 ms |
1868 KB |
Output is correct |
8 |
Correct |
3 ms |
1868 KB |
Output is correct |
9 |
Correct |
50 ms |
5312 KB |
Output is correct |
10 |
Correct |
69 ms |
5692 KB |
Output is correct |
11 |
Correct |
72 ms |
5660 KB |
Output is correct |
12 |
Correct |
84 ms |
5852 KB |
Output is correct |
13 |
Correct |
71 ms |
5852 KB |
Output is correct |
14 |
Execution timed out |
2072 ms |
5468 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1740 KB |
Output is correct |
2 |
Correct |
3 ms |
1740 KB |
Output is correct |
3 |
Execution timed out |
2072 ms |
7144 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1740 KB |
Output is correct |
2 |
Correct |
3 ms |
1740 KB |
Output is correct |
3 |
Correct |
2 ms |
1740 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
4 ms |
1868 KB |
Output is correct |
6 |
Correct |
3 ms |
1900 KB |
Output is correct |
7 |
Correct |
3 ms |
1868 KB |
Output is correct |
8 |
Correct |
3 ms |
1868 KB |
Output is correct |
9 |
Correct |
3 ms |
1740 KB |
Output is correct |
10 |
Correct |
3 ms |
1924 KB |
Output is correct |
11 |
Correct |
3 ms |
1920 KB |
Output is correct |
12 |
Correct |
3 ms |
1868 KB |
Output is correct |
13 |
Correct |
3 ms |
1868 KB |
Output is correct |
14 |
Correct |
3 ms |
1868 KB |
Output is correct |
15 |
Correct |
3 ms |
1868 KB |
Output is correct |
16 |
Correct |
3 ms |
1868 KB |
Output is correct |
17 |
Correct |
3 ms |
1868 KB |
Output is correct |
18 |
Correct |
3 ms |
1868 KB |
Output is correct |
19 |
Correct |
3 ms |
1868 KB |
Output is correct |
20 |
Correct |
3 ms |
1868 KB |
Output is correct |
21 |
Correct |
3 ms |
1868 KB |
Output is correct |
22 |
Correct |
3 ms |
1868 KB |
Output is correct |
23 |
Correct |
3 ms |
1868 KB |
Output is correct |
24 |
Correct |
4 ms |
1868 KB |
Output is correct |
25 |
Correct |
3 ms |
1868 KB |
Output is correct |
26 |
Correct |
4 ms |
1868 KB |
Output is correct |
27 |
Correct |
4 ms |
1868 KB |
Output is correct |
28 |
Correct |
4 ms |
1872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1740 KB |
Output is correct |
2 |
Correct |
2 ms |
1740 KB |
Output is correct |
3 |
Correct |
3 ms |
1740 KB |
Output is correct |
4 |
Correct |
2 ms |
1740 KB |
Output is correct |
5 |
Correct |
4 ms |
1868 KB |
Output is correct |
6 |
Correct |
4 ms |
1868 KB |
Output is correct |
7 |
Correct |
3 ms |
1900 KB |
Output is correct |
8 |
Correct |
3 ms |
1868 KB |
Output is correct |
9 |
Correct |
3 ms |
1868 KB |
Output is correct |
10 |
Correct |
50 ms |
5312 KB |
Output is correct |
11 |
Correct |
69 ms |
5692 KB |
Output is correct |
12 |
Correct |
72 ms |
5660 KB |
Output is correct |
13 |
Correct |
84 ms |
5852 KB |
Output is correct |
14 |
Correct |
71 ms |
5852 KB |
Output is correct |
15 |
Correct |
3 ms |
1924 KB |
Output is correct |
16 |
Correct |
3 ms |
1920 KB |
Output is correct |
17 |
Correct |
3 ms |
1868 KB |
Output is correct |
18 |
Correct |
3 ms |
1868 KB |
Output is correct |
19 |
Correct |
3 ms |
1868 KB |
Output is correct |
20 |
Correct |
3 ms |
1868 KB |
Output is correct |
21 |
Correct |
3 ms |
1868 KB |
Output is correct |
22 |
Correct |
3 ms |
1868 KB |
Output is correct |
23 |
Correct |
3 ms |
1868 KB |
Output is correct |
24 |
Correct |
3 ms |
1868 KB |
Output is correct |
25 |
Correct |
3 ms |
1868 KB |
Output is correct |
26 |
Correct |
3 ms |
1868 KB |
Output is correct |
27 |
Correct |
3 ms |
1868 KB |
Output is correct |
28 |
Correct |
3 ms |
1868 KB |
Output is correct |
29 |
Correct |
4 ms |
1868 KB |
Output is correct |
30 |
Correct |
3 ms |
1868 KB |
Output is correct |
31 |
Correct |
4 ms |
1868 KB |
Output is correct |
32 |
Correct |
4 ms |
1868 KB |
Output is correct |
33 |
Correct |
4 ms |
1872 KB |
Output is correct |
34 |
Correct |
9 ms |
2704 KB |
Output is correct |
35 |
Correct |
77 ms |
7624 KB |
Output is correct |
36 |
Correct |
82 ms |
7628 KB |
Output is correct |
37 |
Correct |
77 ms |
7616 KB |
Output is correct |
38 |
Correct |
78 ms |
7612 KB |
Output is correct |
39 |
Correct |
78 ms |
7592 KB |
Output is correct |
40 |
Correct |
72 ms |
7248 KB |
Output is correct |
41 |
Correct |
82 ms |
7880 KB |
Output is correct |
42 |
Correct |
78 ms |
7616 KB |
Output is correct |
43 |
Correct |
62 ms |
7624 KB |
Output is correct |
44 |
Correct |
85 ms |
7956 KB |
Output is correct |
45 |
Correct |
103 ms |
11576 KB |
Output is correct |
46 |
Correct |
77 ms |
7620 KB |
Output is correct |
47 |
Correct |
82 ms |
7808 KB |
Output is correct |
48 |
Correct |
85 ms |
8124 KB |
Output is correct |
49 |
Correct |
78 ms |
11504 KB |
Output is correct |
50 |
Correct |
62 ms |
8632 KB |
Output is correct |
51 |
Correct |
85 ms |
9232 KB |
Output is correct |
52 |
Correct |
110 ms |
12168 KB |
Output is correct |
53 |
Correct |
116 ms |
12984 KB |
Output is correct |
54 |
Correct |
134 ms |
13636 KB |
Output is correct |
55 |
Correct |
65 ms |
7624 KB |
Output is correct |
56 |
Correct |
131 ms |
12668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1740 KB |
Output is correct |
2 |
Correct |
3 ms |
1740 KB |
Output is correct |
3 |
Correct |
2 ms |
1740 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
4 ms |
1868 KB |
Output is correct |
6 |
Correct |
3 ms |
1900 KB |
Output is correct |
7 |
Correct |
3 ms |
1868 KB |
Output is correct |
8 |
Correct |
3 ms |
1868 KB |
Output is correct |
9 |
Correct |
50 ms |
5312 KB |
Output is correct |
10 |
Correct |
69 ms |
5692 KB |
Output is correct |
11 |
Correct |
72 ms |
5660 KB |
Output is correct |
12 |
Correct |
84 ms |
5852 KB |
Output is correct |
13 |
Correct |
71 ms |
5852 KB |
Output is correct |
14 |
Execution timed out |
2072 ms |
5468 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1740 KB |
Output is correct |
2 |
Correct |
2 ms |
1740 KB |
Output is correct |
3 |
Correct |
3 ms |
1740 KB |
Output is correct |
4 |
Correct |
2 ms |
1740 KB |
Output is correct |
5 |
Correct |
4 ms |
1868 KB |
Output is correct |
6 |
Correct |
4 ms |
1868 KB |
Output is correct |
7 |
Correct |
3 ms |
1900 KB |
Output is correct |
8 |
Correct |
3 ms |
1868 KB |
Output is correct |
9 |
Correct |
3 ms |
1868 KB |
Output is correct |
10 |
Correct |
50 ms |
5312 KB |
Output is correct |
11 |
Correct |
69 ms |
5692 KB |
Output is correct |
12 |
Correct |
72 ms |
5660 KB |
Output is correct |
13 |
Correct |
84 ms |
5852 KB |
Output is correct |
14 |
Correct |
71 ms |
5852 KB |
Output is correct |
15 |
Execution timed out |
2072 ms |
5468 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |