#include "swap.h"
#include <cassert>
#include <cstdio>
#pragma warning(disable : 4996)
#include <map>
#include <iostream>
using namespace std;
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
vi col_v;
vector<vector<pi>> his;
vector<vi> col;
vector<pi> kats;
void uni(int i, int j, int t) {
if (col_v[i] == col_v[j]) {
if (his[i][0].first == -1) {
for (int x : col[col_v[i]]) {
his[x][0] = { t,-1 };
}
}
return;
}
if (col[col_v[i]].size() > col[col_v[j]].size())
swap(i, j);
int c = col_v[j];
int c1 = col_v[i];
if (his[i][0].first != -1) {
if (his[j][0].first == -1) {
for (int x : col[c]) {
his[x][0] = { t,-1 };
}
}
}
else if (his[j][0].first != -1) {
if (his[i][0].first == -1) {
for (int x : col[c1]) {
his[x][0] = { t,-1 };
}
}
}
else if (i == kats[c1].first) {
if (j == kats[c].second) {
kats[c] = { kats[c1].second,kats[c].first };
}
else if (j == kats[c].first) {
kats[c] = { kats[c1].second,kats[c].second };
}
else {
for (int x : col[c1]) {
his[x][0] = { t,-1 };
}
for (int x : col[c]) {
his[x][0] = { t,-1 };
}
}
}
else if (i == kats[c1].second) {
if (j == kats[c].second) {
kats[c] = { kats[c1].first,kats[c].first };
}
else if (j == kats[c].first) {
kats[c] = { kats[c1].first,kats[c].second };
}
else {
for (int x : col[c1]) {
his[x][0] = { t,-1 };
}
for (int x : col[c]) {
his[x][0] = { t,-1 };
}
}
}
else {
for (int x : col[c1]) {
his[x][0] = { t,-1 };
}
for (int x : col[c]) {
his[x][0] = { t,-1 };
}
}
for (int x : col[col_v[i]]) {
col_v[x] = c;
col[col_v[j]].push_back(x);
his[x].push_back({ t,c });
}
}
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
col_v.resize(N);
his.resize(N);
vector<vi> v;
for (int i = 0; i < N; i++) {
his[i].push_back({ -1,-1 });
his[i].push_back({ 0,i });
kats.push_back( { i, i });
}
col.resize(N);
for (int i = 0; i < N; i++) {
col_v[i] = i;
col[i].push_back(i);
}
for (int i = 0; i < M; i++) {
v.push_back({ W[i],V[i],U[i] });
}
sort(v.begin(), v.end());
for (vi vec : v) {
uni(vec[1], vec[2], vec[0]);
}
}
int getMinimumFuelCapacity(int X, int Y) {
vector<pi> v1 = his[X];
vector<pi> v2 = his[Y];
int s = max(v1[0].first, v2[0].first);
int it1 = v1.size() - 1;
int it2= v2.size() - 1;
if (v1[0].first == -1)
return -1;
vector<vi> vec;
for (int i = 1; i <= it1; i++) {
vec.push_back({ v1[i].first,1,i,v1[i].second });
}
for (int i = 1; i <= it2; i++) {
vec.push_back({ v2[i].first,2,i,v2[i].second });
}
sort(vec.begin(), vec.end());
int l1=-1, l2=-1;
for (int i = 0; i < vec.size(); i++) {
int now = vec[i][0];
if (vec[i][1] == 1) {
l1 = vec[i][3];
}
else {
l2 = vec[i][3];
}
if (l1 == l2 ) {
return max(now,s);
}
}
//return vec[vec.size()-1][0];
}
Compilation message
swap.cpp:5: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
5 | #pragma warning(disable : 4996)
|
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:142:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
142 | for (int i = 0; i < vec.size(); i++) {
| ~~^~~~~~~~~~~~
swap.cpp:125:26: warning: control reaches end of non-void function [-Wreturn-type]
125 | vector<pi> v1 = his[X];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
142 ms |
24960 KB |
Output is correct |
10 |
Correct |
216 ms |
30116 KB |
Output is correct |
11 |
Correct |
218 ms |
29420 KB |
Output is correct |
12 |
Correct |
196 ms |
31412 KB |
Output is correct |
13 |
Correct |
142 ms |
23492 KB |
Output is correct |
14 |
Correct |
163 ms |
24980 KB |
Output is correct |
15 |
Correct |
279 ms |
32140 KB |
Output is correct |
16 |
Correct |
305 ms |
31208 KB |
Output is correct |
17 |
Correct |
285 ms |
33328 KB |
Output is correct |
18 |
Correct |
248 ms |
25144 KB |
Output is correct |
19 |
Correct |
179 ms |
7884 KB |
Output is correct |
20 |
Correct |
447 ms |
32312 KB |
Output is correct |
21 |
Correct |
433 ms |
31056 KB |
Output is correct |
22 |
Correct |
467 ms |
33304 KB |
Output is correct |
23 |
Correct |
323 ms |
25156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
226 ms |
23316 KB |
Output is correct |
4 |
Correct |
264 ms |
24452 KB |
Output is correct |
5 |
Correct |
231 ms |
23764 KB |
Output is correct |
6 |
Correct |
250 ms |
24332 KB |
Output is correct |
7 |
Correct |
239 ms |
24156 KB |
Output is correct |
8 |
Correct |
227 ms |
23108 KB |
Output is correct |
9 |
Correct |
263 ms |
24152 KB |
Output is correct |
10 |
Correct |
223 ms |
22968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
596 KB |
Output is correct |
25 |
Correct |
2 ms |
596 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
142 ms |
24960 KB |
Output is correct |
11 |
Correct |
216 ms |
30116 KB |
Output is correct |
12 |
Correct |
218 ms |
29420 KB |
Output is correct |
13 |
Correct |
196 ms |
31412 KB |
Output is correct |
14 |
Correct |
142 ms |
23492 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
596 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
2 ms |
540 KB |
Output is correct |
34 |
Correct |
21 ms |
4112 KB |
Output is correct |
35 |
Correct |
193 ms |
31272 KB |
Output is correct |
36 |
Correct |
203 ms |
30756 KB |
Output is correct |
37 |
Correct |
207 ms |
30020 KB |
Output is correct |
38 |
Correct |
174 ms |
28964 KB |
Output is correct |
39 |
Correct |
208 ms |
28552 KB |
Output is correct |
40 |
Correct |
181 ms |
25924 KB |
Output is correct |
41 |
Correct |
196 ms |
31860 KB |
Output is correct |
42 |
Correct |
220 ms |
31908 KB |
Output is correct |
43 |
Correct |
122 ms |
23608 KB |
Output is correct |
44 |
Correct |
184 ms |
28512 KB |
Output is correct |
45 |
Correct |
180 ms |
24896 KB |
Output is correct |
46 |
Correct |
228 ms |
30776 KB |
Output is correct |
47 |
Correct |
159 ms |
27600 KB |
Output is correct |
48 |
Correct |
156 ms |
24988 KB |
Output is correct |
49 |
Correct |
94 ms |
14360 KB |
Output is correct |
50 |
Correct |
79 ms |
10968 KB |
Output is correct |
51 |
Correct |
130 ms |
20860 KB |
Output is correct |
52 |
Correct |
256 ms |
34544 KB |
Output is correct |
53 |
Correct |
228 ms |
32284 KB |
Output is correct |
54 |
Correct |
307 ms |
39480 KB |
Output is correct |
55 |
Correct |
116 ms |
23608 KB |
Output is correct |
56 |
Correct |
220 ms |
30436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
142 ms |
24960 KB |
Output is correct |
10 |
Correct |
216 ms |
30116 KB |
Output is correct |
11 |
Correct |
218 ms |
29420 KB |
Output is correct |
12 |
Correct |
196 ms |
31412 KB |
Output is correct |
13 |
Correct |
142 ms |
23492 KB |
Output is correct |
14 |
Correct |
163 ms |
24980 KB |
Output is correct |
15 |
Correct |
279 ms |
32140 KB |
Output is correct |
16 |
Correct |
305 ms |
31208 KB |
Output is correct |
17 |
Correct |
285 ms |
33328 KB |
Output is correct |
18 |
Correct |
248 ms |
25144 KB |
Output is correct |
19 |
Correct |
226 ms |
23316 KB |
Output is correct |
20 |
Correct |
264 ms |
24452 KB |
Output is correct |
21 |
Correct |
231 ms |
23764 KB |
Output is correct |
22 |
Correct |
250 ms |
24332 KB |
Output is correct |
23 |
Correct |
239 ms |
24156 KB |
Output is correct |
24 |
Correct |
227 ms |
23108 KB |
Output is correct |
25 |
Correct |
263 ms |
24152 KB |
Output is correct |
26 |
Correct |
223 ms |
22968 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
21 ms |
4112 KB |
Output is correct |
37 |
Correct |
193 ms |
31272 KB |
Output is correct |
38 |
Correct |
203 ms |
30756 KB |
Output is correct |
39 |
Correct |
207 ms |
30020 KB |
Output is correct |
40 |
Correct |
174 ms |
28964 KB |
Output is correct |
41 |
Correct |
208 ms |
28552 KB |
Output is correct |
42 |
Correct |
181 ms |
25924 KB |
Output is correct |
43 |
Correct |
196 ms |
31860 KB |
Output is correct |
44 |
Correct |
220 ms |
31908 KB |
Output is correct |
45 |
Correct |
122 ms |
23608 KB |
Output is correct |
46 |
Correct |
184 ms |
28512 KB |
Output is correct |
47 |
Correct |
33 ms |
3916 KB |
Output is correct |
48 |
Correct |
453 ms |
32944 KB |
Output is correct |
49 |
Correct |
448 ms |
31916 KB |
Output is correct |
50 |
Correct |
438 ms |
31928 KB |
Output is correct |
51 |
Correct |
417 ms |
30908 KB |
Output is correct |
52 |
Correct |
419 ms |
28620 KB |
Output is correct |
53 |
Correct |
370 ms |
20508 KB |
Output is correct |
54 |
Correct |
472 ms |
32752 KB |
Output is correct |
55 |
Correct |
476 ms |
33588 KB |
Output is correct |
56 |
Correct |
253 ms |
25220 KB |
Output is correct |
57 |
Correct |
428 ms |
34328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
142 ms |
24960 KB |
Output is correct |
11 |
Correct |
216 ms |
30116 KB |
Output is correct |
12 |
Correct |
218 ms |
29420 KB |
Output is correct |
13 |
Correct |
196 ms |
31412 KB |
Output is correct |
14 |
Correct |
142 ms |
23492 KB |
Output is correct |
15 |
Correct |
163 ms |
24980 KB |
Output is correct |
16 |
Correct |
279 ms |
32140 KB |
Output is correct |
17 |
Correct |
305 ms |
31208 KB |
Output is correct |
18 |
Correct |
285 ms |
33328 KB |
Output is correct |
19 |
Correct |
248 ms |
25144 KB |
Output is correct |
20 |
Correct |
226 ms |
23316 KB |
Output is correct |
21 |
Correct |
264 ms |
24452 KB |
Output is correct |
22 |
Correct |
231 ms |
23764 KB |
Output is correct |
23 |
Correct |
250 ms |
24332 KB |
Output is correct |
24 |
Correct |
239 ms |
24156 KB |
Output is correct |
25 |
Correct |
227 ms |
23108 KB |
Output is correct |
26 |
Correct |
263 ms |
24152 KB |
Output is correct |
27 |
Correct |
223 ms |
22968 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
21 ms |
4112 KB |
Output is correct |
38 |
Correct |
193 ms |
31272 KB |
Output is correct |
39 |
Correct |
203 ms |
30756 KB |
Output is correct |
40 |
Correct |
207 ms |
30020 KB |
Output is correct |
41 |
Correct |
174 ms |
28964 KB |
Output is correct |
42 |
Correct |
208 ms |
28552 KB |
Output is correct |
43 |
Correct |
181 ms |
25924 KB |
Output is correct |
44 |
Correct |
196 ms |
31860 KB |
Output is correct |
45 |
Correct |
220 ms |
31908 KB |
Output is correct |
46 |
Correct |
122 ms |
23608 KB |
Output is correct |
47 |
Correct |
184 ms |
28512 KB |
Output is correct |
48 |
Correct |
33 ms |
3916 KB |
Output is correct |
49 |
Correct |
453 ms |
32944 KB |
Output is correct |
50 |
Correct |
448 ms |
31916 KB |
Output is correct |
51 |
Correct |
438 ms |
31928 KB |
Output is correct |
52 |
Correct |
417 ms |
30908 KB |
Output is correct |
53 |
Correct |
419 ms |
28620 KB |
Output is correct |
54 |
Correct |
370 ms |
20508 KB |
Output is correct |
55 |
Correct |
472 ms |
32752 KB |
Output is correct |
56 |
Correct |
476 ms |
33588 KB |
Output is correct |
57 |
Correct |
253 ms |
25220 KB |
Output is correct |
58 |
Correct |
428 ms |
34328 KB |
Output is correct |
59 |
Correct |
179 ms |
7884 KB |
Output is correct |
60 |
Correct |
447 ms |
32312 KB |
Output is correct |
61 |
Correct |
433 ms |
31056 KB |
Output is correct |
62 |
Correct |
467 ms |
33304 KB |
Output is correct |
63 |
Correct |
323 ms |
25156 KB |
Output is correct |
64 |
Correct |
1 ms |
468 KB |
Output is correct |
65 |
Correct |
1 ms |
468 KB |
Output is correct |
66 |
Correct |
1 ms |
468 KB |
Output is correct |
67 |
Correct |
1 ms |
468 KB |
Output is correct |
68 |
Correct |
1 ms |
468 KB |
Output is correct |
69 |
Correct |
2 ms |
596 KB |
Output is correct |
70 |
Correct |
2 ms |
596 KB |
Output is correct |
71 |
Correct |
2 ms |
596 KB |
Output is correct |
72 |
Correct |
1 ms |
468 KB |
Output is correct |
73 |
Correct |
2 ms |
540 KB |
Output is correct |
74 |
Correct |
180 ms |
24896 KB |
Output is correct |
75 |
Correct |
228 ms |
30776 KB |
Output is correct |
76 |
Correct |
159 ms |
27600 KB |
Output is correct |
77 |
Correct |
156 ms |
24988 KB |
Output is correct |
78 |
Correct |
94 ms |
14360 KB |
Output is correct |
79 |
Correct |
79 ms |
10968 KB |
Output is correct |
80 |
Correct |
130 ms |
20860 KB |
Output is correct |
81 |
Correct |
256 ms |
34544 KB |
Output is correct |
82 |
Correct |
228 ms |
32284 KB |
Output is correct |
83 |
Correct |
307 ms |
39480 KB |
Output is correct |
84 |
Correct |
116 ms |
23608 KB |
Output is correct |
85 |
Correct |
220 ms |
30436 KB |
Output is correct |
86 |
Correct |
83 ms |
11416 KB |
Output is correct |
87 |
Correct |
462 ms |
35356 KB |
Output is correct |
88 |
Correct |
419 ms |
35580 KB |
Output is correct |
89 |
Correct |
314 ms |
29468 KB |
Output is correct |
90 |
Correct |
227 ms |
20980 KB |
Output is correct |
91 |
Correct |
254 ms |
21800 KB |
Output is correct |
92 |
Correct |
271 ms |
26784 KB |
Output is correct |
93 |
Correct |
483 ms |
40880 KB |
Output is correct |
94 |
Correct |
450 ms |
40088 KB |
Output is correct |
95 |
Correct |
576 ms |
47852 KB |
Output is correct |
96 |
Correct |
259 ms |
29240 KB |
Output is correct |
97 |
Correct |
364 ms |
34448 KB |
Output is correct |