#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,v1[i].second,1});
}
for (int i = 1; i <= it2; i++) {
vec.push_back({ v2[i].first,v2[i].second,2 });
}
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][2] == 1) {
l1 = vec[i][1];
}
else {
l2 = vec[i][1];
}
if (l1 == l2 ) {
return max(now,s);
}
}
return -1;
}
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++) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
153 ms |
25064 KB |
Output is correct |
10 |
Correct |
181 ms |
30112 KB |
Output is correct |
11 |
Correct |
182 ms |
29432 KB |
Output is correct |
12 |
Correct |
189 ms |
31332 KB |
Output is correct |
13 |
Correct |
123 ms |
23568 KB |
Output is correct |
14 |
Correct |
147 ms |
25300 KB |
Output is correct |
15 |
Correct |
280 ms |
32312 KB |
Output is correct |
16 |
Correct |
262 ms |
31220 KB |
Output is correct |
17 |
Correct |
328 ms |
33352 KB |
Output is correct |
18 |
Correct |
192 ms |
25160 KB |
Output is correct |
19 |
Correct |
169 ms |
7976 KB |
Output is correct |
20 |
Correct |
405 ms |
32280 KB |
Output is correct |
21 |
Correct |
423 ms |
31072 KB |
Output is correct |
22 |
Correct |
436 ms |
33352 KB |
Output is correct |
23 |
Correct |
260 ms |
25140 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 |
222 ms |
23372 KB |
Output is correct |
4 |
Correct |
226 ms |
24520 KB |
Output is correct |
5 |
Correct |
222 ms |
23708 KB |
Output is correct |
6 |
Correct |
218 ms |
24376 KB |
Output is correct |
7 |
Correct |
234 ms |
24120 KB |
Output is correct |
8 |
Correct |
222 ms |
23112 KB |
Output is correct |
9 |
Correct |
246 ms |
24020 KB |
Output is correct |
10 |
Correct |
220 ms |
22876 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 |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 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 |
2 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 |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
596 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 |
153 ms |
25064 KB |
Output is correct |
11 |
Correct |
181 ms |
30112 KB |
Output is correct |
12 |
Correct |
182 ms |
29432 KB |
Output is correct |
13 |
Correct |
189 ms |
31332 KB |
Output is correct |
14 |
Correct |
123 ms |
23568 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 |
2 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 |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
2 ms |
596 KB |
Output is correct |
34 |
Correct |
14 ms |
4008 KB |
Output is correct |
35 |
Correct |
189 ms |
31152 KB |
Output is correct |
36 |
Correct |
193 ms |
30692 KB |
Output is correct |
37 |
Correct |
179 ms |
30036 KB |
Output is correct |
38 |
Correct |
174 ms |
28956 KB |
Output is correct |
39 |
Correct |
179 ms |
28508 KB |
Output is correct |
40 |
Correct |
168 ms |
25916 KB |
Output is correct |
41 |
Correct |
207 ms |
31832 KB |
Output is correct |
42 |
Correct |
192 ms |
31788 KB |
Output is correct |
43 |
Correct |
116 ms |
23640 KB |
Output is correct |
44 |
Correct |
173 ms |
28464 KB |
Output is correct |
45 |
Correct |
152 ms |
24880 KB |
Output is correct |
46 |
Correct |
186 ms |
30776 KB |
Output is correct |
47 |
Correct |
160 ms |
27684 KB |
Output is correct |
48 |
Correct |
142 ms |
24888 KB |
Output is correct |
49 |
Correct |
88 ms |
14356 KB |
Output is correct |
50 |
Correct |
68 ms |
10900 KB |
Output is correct |
51 |
Correct |
125 ms |
20752 KB |
Output is correct |
52 |
Correct |
222 ms |
34352 KB |
Output is correct |
53 |
Correct |
216 ms |
32288 KB |
Output is correct |
54 |
Correct |
266 ms |
39584 KB |
Output is correct |
55 |
Correct |
117 ms |
23472 KB |
Output is correct |
56 |
Correct |
197 ms |
30304 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 |
153 ms |
25064 KB |
Output is correct |
10 |
Correct |
181 ms |
30112 KB |
Output is correct |
11 |
Correct |
182 ms |
29432 KB |
Output is correct |
12 |
Correct |
189 ms |
31332 KB |
Output is correct |
13 |
Correct |
123 ms |
23568 KB |
Output is correct |
14 |
Correct |
147 ms |
25300 KB |
Output is correct |
15 |
Correct |
280 ms |
32312 KB |
Output is correct |
16 |
Correct |
262 ms |
31220 KB |
Output is correct |
17 |
Correct |
328 ms |
33352 KB |
Output is correct |
18 |
Correct |
192 ms |
25160 KB |
Output is correct |
19 |
Correct |
222 ms |
23372 KB |
Output is correct |
20 |
Correct |
226 ms |
24520 KB |
Output is correct |
21 |
Correct |
222 ms |
23708 KB |
Output is correct |
22 |
Correct |
218 ms |
24376 KB |
Output is correct |
23 |
Correct |
234 ms |
24120 KB |
Output is correct |
24 |
Correct |
222 ms |
23112 KB |
Output is correct |
25 |
Correct |
246 ms |
24020 KB |
Output is correct |
26 |
Correct |
220 ms |
22876 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 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 |
2 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 |
14 ms |
4008 KB |
Output is correct |
37 |
Correct |
189 ms |
31152 KB |
Output is correct |
38 |
Correct |
193 ms |
30692 KB |
Output is correct |
39 |
Correct |
179 ms |
30036 KB |
Output is correct |
40 |
Correct |
174 ms |
28956 KB |
Output is correct |
41 |
Correct |
179 ms |
28508 KB |
Output is correct |
42 |
Correct |
168 ms |
25916 KB |
Output is correct |
43 |
Correct |
207 ms |
31832 KB |
Output is correct |
44 |
Correct |
192 ms |
31788 KB |
Output is correct |
45 |
Correct |
116 ms |
23640 KB |
Output is correct |
46 |
Correct |
173 ms |
28464 KB |
Output is correct |
47 |
Correct |
31 ms |
3920 KB |
Output is correct |
48 |
Correct |
437 ms |
32836 KB |
Output is correct |
49 |
Correct |
423 ms |
31920 KB |
Output is correct |
50 |
Correct |
435 ms |
31820 KB |
Output is correct |
51 |
Correct |
405 ms |
30904 KB |
Output is correct |
52 |
Correct |
375 ms |
28652 KB |
Output is correct |
53 |
Correct |
287 ms |
20540 KB |
Output is correct |
54 |
Correct |
428 ms |
32720 KB |
Output is correct |
55 |
Correct |
445 ms |
33608 KB |
Output is correct |
56 |
Incorrect |
260 ms |
25160 KB |
Output isn't correct |
57 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
153 ms |
25064 KB |
Output is correct |
11 |
Correct |
181 ms |
30112 KB |
Output is correct |
12 |
Correct |
182 ms |
29432 KB |
Output is correct |
13 |
Correct |
189 ms |
31332 KB |
Output is correct |
14 |
Correct |
123 ms |
23568 KB |
Output is correct |
15 |
Correct |
147 ms |
25300 KB |
Output is correct |
16 |
Correct |
280 ms |
32312 KB |
Output is correct |
17 |
Correct |
262 ms |
31220 KB |
Output is correct |
18 |
Correct |
328 ms |
33352 KB |
Output is correct |
19 |
Correct |
192 ms |
25160 KB |
Output is correct |
20 |
Correct |
222 ms |
23372 KB |
Output is correct |
21 |
Correct |
226 ms |
24520 KB |
Output is correct |
22 |
Correct |
222 ms |
23708 KB |
Output is correct |
23 |
Correct |
218 ms |
24376 KB |
Output is correct |
24 |
Correct |
234 ms |
24120 KB |
Output is correct |
25 |
Correct |
222 ms |
23112 KB |
Output is correct |
26 |
Correct |
246 ms |
24020 KB |
Output is correct |
27 |
Correct |
220 ms |
22876 KB |
Output is correct |
28 |
Correct |
1 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 |
2 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 |
14 ms |
4008 KB |
Output is correct |
38 |
Correct |
189 ms |
31152 KB |
Output is correct |
39 |
Correct |
193 ms |
30692 KB |
Output is correct |
40 |
Correct |
179 ms |
30036 KB |
Output is correct |
41 |
Correct |
174 ms |
28956 KB |
Output is correct |
42 |
Correct |
179 ms |
28508 KB |
Output is correct |
43 |
Correct |
168 ms |
25916 KB |
Output is correct |
44 |
Correct |
207 ms |
31832 KB |
Output is correct |
45 |
Correct |
192 ms |
31788 KB |
Output is correct |
46 |
Correct |
116 ms |
23640 KB |
Output is correct |
47 |
Correct |
173 ms |
28464 KB |
Output is correct |
48 |
Correct |
31 ms |
3920 KB |
Output is correct |
49 |
Correct |
437 ms |
32836 KB |
Output is correct |
50 |
Correct |
423 ms |
31920 KB |
Output is correct |
51 |
Correct |
435 ms |
31820 KB |
Output is correct |
52 |
Correct |
405 ms |
30904 KB |
Output is correct |
53 |
Correct |
375 ms |
28652 KB |
Output is correct |
54 |
Correct |
287 ms |
20540 KB |
Output is correct |
55 |
Correct |
428 ms |
32720 KB |
Output is correct |
56 |
Correct |
445 ms |
33608 KB |
Output is correct |
57 |
Incorrect |
260 ms |
25160 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |