#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,v1[i].second });
}
for (int i = 1; i <= it2; i++) {
vec.push_back({ v2[i].first,2,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][2];
}
else {
l2 = vec[i][2];
}
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++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
568 KB |
Output is correct |
7 |
Correct |
2 ms |
572 KB |
Output is correct |
8 |
Correct |
1 ms |
568 KB |
Output is correct |
9 |
Correct |
188 ms |
25128 KB |
Output is correct |
10 |
Correct |
238 ms |
30212 KB |
Output is correct |
11 |
Correct |
223 ms |
29588 KB |
Output is correct |
12 |
Correct |
236 ms |
31500 KB |
Output is correct |
13 |
Correct |
142 ms |
23692 KB |
Output is correct |
14 |
Correct |
185 ms |
25120 KB |
Output is correct |
15 |
Correct |
322 ms |
32320 KB |
Output is correct |
16 |
Correct |
333 ms |
31328 KB |
Output is correct |
17 |
Correct |
346 ms |
33484 KB |
Output is correct |
18 |
Correct |
237 ms |
25184 KB |
Output is correct |
19 |
Correct |
195 ms |
8092 KB |
Output is correct |
20 |
Correct |
500 ms |
32440 KB |
Output is correct |
21 |
Correct |
562 ms |
31172 KB |
Output is correct |
22 |
Correct |
554 ms |
33356 KB |
Output is correct |
23 |
Correct |
322 ms |
25268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
260 ms |
23456 KB |
Output is correct |
4 |
Correct |
262 ms |
24636 KB |
Output is correct |
5 |
Correct |
279 ms |
23876 KB |
Output is correct |
6 |
Correct |
251 ms |
24488 KB |
Output is correct |
7 |
Correct |
280 ms |
24220 KB |
Output is correct |
8 |
Correct |
273 ms |
23284 KB |
Output is correct |
9 |
Correct |
285 ms |
24184 KB |
Output is correct |
10 |
Correct |
284 ms |
23024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
568 KB |
Output is correct |
7 |
Correct |
2 ms |
572 KB |
Output is correct |
8 |
Correct |
1 ms |
568 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
572 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
564 KB |
Output is correct |
13 |
Correct |
2 ms |
436 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
564 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
596 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 |
436 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 |
564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
568 KB |
Output is correct |
8 |
Correct |
2 ms |
572 KB |
Output is correct |
9 |
Correct |
1 ms |
568 KB |
Output is correct |
10 |
Correct |
188 ms |
25128 KB |
Output is correct |
11 |
Correct |
238 ms |
30212 KB |
Output is correct |
12 |
Correct |
223 ms |
29588 KB |
Output is correct |
13 |
Correct |
236 ms |
31500 KB |
Output is correct |
14 |
Correct |
142 ms |
23692 KB |
Output is correct |
15 |
Correct |
2 ms |
572 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
564 KB |
Output is correct |
18 |
Correct |
2 ms |
436 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
564 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
596 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 |
436 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 |
564 KB |
Output is correct |
34 |
Correct |
17 ms |
4168 KB |
Output is correct |
35 |
Correct |
224 ms |
31288 KB |
Output is correct |
36 |
Correct |
236 ms |
30896 KB |
Output is correct |
37 |
Correct |
211 ms |
30128 KB |
Output is correct |
38 |
Correct |
197 ms |
28972 KB |
Output is correct |
39 |
Correct |
210 ms |
28628 KB |
Output is correct |
40 |
Correct |
177 ms |
26064 KB |
Output is correct |
41 |
Correct |
239 ms |
31988 KB |
Output is correct |
42 |
Correct |
236 ms |
32052 KB |
Output is correct |
43 |
Correct |
131 ms |
23748 KB |
Output is correct |
44 |
Correct |
228 ms |
28548 KB |
Output is correct |
45 |
Correct |
196 ms |
25060 KB |
Output is correct |
46 |
Correct |
246 ms |
30876 KB |
Output is correct |
47 |
Correct |
187 ms |
27800 KB |
Output is correct |
48 |
Correct |
162 ms |
25076 KB |
Output is correct |
49 |
Correct |
107 ms |
14544 KB |
Output is correct |
50 |
Correct |
80 ms |
11100 KB |
Output is correct |
51 |
Correct |
146 ms |
20972 KB |
Output is correct |
52 |
Correct |
283 ms |
34524 KB |
Output is correct |
53 |
Correct |
265 ms |
32344 KB |
Output is correct |
54 |
Correct |
326 ms |
39608 KB |
Output is correct |
55 |
Correct |
140 ms |
23600 KB |
Output is correct |
56 |
Correct |
256 ms |
30556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
568 KB |
Output is correct |
7 |
Correct |
2 ms |
572 KB |
Output is correct |
8 |
Correct |
1 ms |
568 KB |
Output is correct |
9 |
Correct |
188 ms |
25128 KB |
Output is correct |
10 |
Correct |
238 ms |
30212 KB |
Output is correct |
11 |
Correct |
223 ms |
29588 KB |
Output is correct |
12 |
Correct |
236 ms |
31500 KB |
Output is correct |
13 |
Correct |
142 ms |
23692 KB |
Output is correct |
14 |
Correct |
185 ms |
25120 KB |
Output is correct |
15 |
Correct |
322 ms |
32320 KB |
Output is correct |
16 |
Correct |
333 ms |
31328 KB |
Output is correct |
17 |
Correct |
346 ms |
33484 KB |
Output is correct |
18 |
Correct |
237 ms |
25184 KB |
Output is correct |
19 |
Correct |
260 ms |
23456 KB |
Output is correct |
20 |
Correct |
262 ms |
24636 KB |
Output is correct |
21 |
Correct |
279 ms |
23876 KB |
Output is correct |
22 |
Correct |
251 ms |
24488 KB |
Output is correct |
23 |
Correct |
280 ms |
24220 KB |
Output is correct |
24 |
Correct |
273 ms |
23284 KB |
Output is correct |
25 |
Correct |
285 ms |
24184 KB |
Output is correct |
26 |
Correct |
284 ms |
23024 KB |
Output is correct |
27 |
Correct |
2 ms |
572 KB |
Output is correct |
28 |
Correct |
2 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
564 KB |
Output is correct |
30 |
Correct |
2 ms |
436 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
2 ms |
564 KB |
Output is correct |
36 |
Correct |
17 ms |
4168 KB |
Output is correct |
37 |
Correct |
224 ms |
31288 KB |
Output is correct |
38 |
Correct |
236 ms |
30896 KB |
Output is correct |
39 |
Correct |
211 ms |
30128 KB |
Output is correct |
40 |
Correct |
197 ms |
28972 KB |
Output is correct |
41 |
Correct |
210 ms |
28628 KB |
Output is correct |
42 |
Correct |
177 ms |
26064 KB |
Output is correct |
43 |
Correct |
239 ms |
31988 KB |
Output is correct |
44 |
Correct |
236 ms |
32052 KB |
Output is correct |
45 |
Correct |
131 ms |
23748 KB |
Output is correct |
46 |
Correct |
228 ms |
28548 KB |
Output is correct |
47 |
Correct |
42 ms |
3988 KB |
Output is correct |
48 |
Correct |
573 ms |
32972 KB |
Output is correct |
49 |
Correct |
518 ms |
32028 KB |
Output is correct |
50 |
Correct |
485 ms |
32028 KB |
Output is correct |
51 |
Correct |
480 ms |
31172 KB |
Output is correct |
52 |
Correct |
486 ms |
28724 KB |
Output is correct |
53 |
Correct |
367 ms |
20628 KB |
Output is correct |
54 |
Correct |
531 ms |
32880 KB |
Output is correct |
55 |
Correct |
541 ms |
33796 KB |
Output is correct |
56 |
Incorrect |
334 ms |
25176 KB |
Output isn't correct |
57 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
568 KB |
Output is correct |
8 |
Correct |
2 ms |
572 KB |
Output is correct |
9 |
Correct |
1 ms |
568 KB |
Output is correct |
10 |
Correct |
188 ms |
25128 KB |
Output is correct |
11 |
Correct |
238 ms |
30212 KB |
Output is correct |
12 |
Correct |
223 ms |
29588 KB |
Output is correct |
13 |
Correct |
236 ms |
31500 KB |
Output is correct |
14 |
Correct |
142 ms |
23692 KB |
Output is correct |
15 |
Correct |
185 ms |
25120 KB |
Output is correct |
16 |
Correct |
322 ms |
32320 KB |
Output is correct |
17 |
Correct |
333 ms |
31328 KB |
Output is correct |
18 |
Correct |
346 ms |
33484 KB |
Output is correct |
19 |
Correct |
237 ms |
25184 KB |
Output is correct |
20 |
Correct |
260 ms |
23456 KB |
Output is correct |
21 |
Correct |
262 ms |
24636 KB |
Output is correct |
22 |
Correct |
279 ms |
23876 KB |
Output is correct |
23 |
Correct |
251 ms |
24488 KB |
Output is correct |
24 |
Correct |
280 ms |
24220 KB |
Output is correct |
25 |
Correct |
273 ms |
23284 KB |
Output is correct |
26 |
Correct |
285 ms |
24184 KB |
Output is correct |
27 |
Correct |
284 ms |
23024 KB |
Output is correct |
28 |
Correct |
2 ms |
572 KB |
Output is correct |
29 |
Correct |
2 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
564 KB |
Output is correct |
31 |
Correct |
2 ms |
436 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
2 ms |
596 KB |
Output is correct |
34 |
Correct |
2 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
2 ms |
564 KB |
Output is correct |
37 |
Correct |
17 ms |
4168 KB |
Output is correct |
38 |
Correct |
224 ms |
31288 KB |
Output is correct |
39 |
Correct |
236 ms |
30896 KB |
Output is correct |
40 |
Correct |
211 ms |
30128 KB |
Output is correct |
41 |
Correct |
197 ms |
28972 KB |
Output is correct |
42 |
Correct |
210 ms |
28628 KB |
Output is correct |
43 |
Correct |
177 ms |
26064 KB |
Output is correct |
44 |
Correct |
239 ms |
31988 KB |
Output is correct |
45 |
Correct |
236 ms |
32052 KB |
Output is correct |
46 |
Correct |
131 ms |
23748 KB |
Output is correct |
47 |
Correct |
228 ms |
28548 KB |
Output is correct |
48 |
Correct |
42 ms |
3988 KB |
Output is correct |
49 |
Correct |
573 ms |
32972 KB |
Output is correct |
50 |
Correct |
518 ms |
32028 KB |
Output is correct |
51 |
Correct |
485 ms |
32028 KB |
Output is correct |
52 |
Correct |
480 ms |
31172 KB |
Output is correct |
53 |
Correct |
486 ms |
28724 KB |
Output is correct |
54 |
Correct |
367 ms |
20628 KB |
Output is correct |
55 |
Correct |
531 ms |
32880 KB |
Output is correct |
56 |
Correct |
541 ms |
33796 KB |
Output is correct |
57 |
Incorrect |
334 ms |
25176 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |