/*
Mayoeba Yabureru
*/
#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
static vector<int> _u, _v, _a, _b;
int construct_roads(vector<int> x, vector<int> y) {
int n = x.size();
vector<vector<int>> gr(n + 1);
vector<int> dsu(n + 1);
map<pair<int, int>, int> mp;
map<pair<int, int>, pair<int, int>> mpp;
vector<pair<int, int>> vv;
x.insert(x.begin(), 0);
y.insert(y.begin(), 0);
for (int i = 1; i <= n; i ++) {
mp[{x[i], y[i]}] = i;
vv.push_back({x[i], y[i]});
dsu[i] = i;
}
vector<int> u, v, a, b;
map<pair<int, int>, int> taken;
map<pair<int, int>, int> connected;
function<int(int)> fp = [&](int x) {
if (dsu[x] == x) return x;
return dsu[x] = fp(dsu[x]);
};
sort(vv.begin(), vv.end());
for (int i = 0; i < n; i ++) {
auto xx = make_pair(vv[i].first, vv[i].second + 2);
if (mp[xx]) {
int fx = fp(mp[vv[i]]), fy = fp(mp[xx]);
if (fx != fy) {
u.push_back(mp[vv[i]]);
v.push_back(mp[xx]);
gr[mp[vv[i]]].push_back(mp[xx]);
gr[mp[xx]].push_back(mp[vv[i]]);
dsu[fx] = fy;
connected[{mp[vv[i]], mp[xx]}] = 1;
connected[{mp[xx], mp[vv[i]]}] = 1;
int ad = vv[i].second % 4;
mpp[{mp[vv[i]], mp[xx]}] = {vv[i].first - 1 + ad, vv[i].second + 1};
taken[{vv[i].first - 1 + ad, vv[i].second + 1}] = 1;
}
}
}
for (int i = 0; i < n; i ++) {
auto xx = make_pair(vv[i].first + 2, vv[i].second);
if (mp[xx]) {
int fx = fp(mp[vv[i]]), fy = fp(mp[xx]);
if (fx != fy) {
u.push_back(mp[vv[i]]);
v.push_back(mp[xx]);
gr[mp[vv[i]]].push_back(mp[xx]);
gr[mp[xx]].push_back(mp[vv[i]]);
dsu[fx] = fy;
connected[{mp[vv[i]], mp[xx]}] = 1;
connected[{mp[xx], mp[vv[i]]}] = 1;
if (taken[{vv[i].first + 1, vv[i].second + 1}] == 0) {
mpp[{mp[vv[i]], mp[xx]}] = {vv[i].first + 1, vv[i].second + 1};
taken[{vv[i].first + 1, vv[i].second + 1}] = 1;
}
else if (taken[{vv[i].first + 1, vv[i].second - 1}] == 0) {
mpp[{mp[vv[i]], mp[xx]}] = {vv[i].first + 1, vv[i].second - 1};
taken[{vv[i].first + 1, vv[i].second - 1}] = 1;
}
else assert(0);
}
}
}
int num = 0, st = 1;
vector<int> vis(n + 1);
function<void(int)> go = [&] (int v) {
num ++;
vis[v] = 1;
for (auto u : gr[v]) {
if (vis[u] == 0) go(u);
}
};
go(st);
for (int i = 0; i < u.size(); i ++) {
a.push_back(mpp[{u[i], v[i]}].first);
b.push_back(mpp[{u[i], v[i]}].second);
u[i] --;
v[i] --;
}
if (num == n) {
build(u, v, a, b);
return 1;
}
return 0;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:89:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for (int i = 0; i < u.size(); i ++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
416 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
466 ms |
58364 KB |
Output is correct |
10 |
Correct |
26 ms |
6236 KB |
Output is correct |
11 |
Correct |
147 ms |
31708 KB |
Output is correct |
12 |
Correct |
41 ms |
9040 KB |
Output is correct |
13 |
Correct |
108 ms |
23952 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
4 ms |
1216 KB |
Output is correct |
16 |
Correct |
437 ms |
55832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
416 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
466 ms |
58364 KB |
Output is correct |
10 |
Correct |
26 ms |
6236 KB |
Output is correct |
11 |
Correct |
147 ms |
31708 KB |
Output is correct |
12 |
Correct |
41 ms |
9040 KB |
Output is correct |
13 |
Correct |
108 ms |
23952 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
4 ms |
1216 KB |
Output is correct |
16 |
Correct |
437 ms |
55832 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
432 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1086 ms |
109900 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Runtime error |
7 ms |
3032 KB |
Execution killed with signal 6 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
416 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
466 ms |
58364 KB |
Output is correct |
10 |
Correct |
26 ms |
6236 KB |
Output is correct |
11 |
Correct |
147 ms |
31708 KB |
Output is correct |
12 |
Correct |
41 ms |
9040 KB |
Output is correct |
13 |
Correct |
108 ms |
23952 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
4 ms |
1216 KB |
Output is correct |
16 |
Correct |
437 ms |
55832 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
432 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1086 ms |
109900 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Runtime error |
7 ms |
3032 KB |
Execution killed with signal 6 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
416 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
466 ms |
58364 KB |
Output is correct |
10 |
Correct |
26 ms |
6236 KB |
Output is correct |
11 |
Correct |
147 ms |
31708 KB |
Output is correct |
12 |
Correct |
41 ms |
9040 KB |
Output is correct |
13 |
Correct |
108 ms |
23952 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
4 ms |
1216 KB |
Output is correct |
16 |
Correct |
437 ms |
55832 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Runtime error |
470 ms |
126800 KB |
Execution killed with signal 6 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
416 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
466 ms |
58364 KB |
Output is correct |
10 |
Correct |
26 ms |
6236 KB |
Output is correct |
11 |
Correct |
147 ms |
31708 KB |
Output is correct |
12 |
Correct |
41 ms |
9040 KB |
Output is correct |
13 |
Correct |
108 ms |
23952 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
4 ms |
1216 KB |
Output is correct |
16 |
Correct |
437 ms |
55832 KB |
Output is correct |
17 |
Correct |
1116 ms |
116780 KB |
Output is correct |
18 |
Correct |
1092 ms |
113092 KB |
Output is correct |
19 |
Runtime error |
470 ms |
126628 KB |
Execution killed with signal 6 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
416 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
466 ms |
58364 KB |
Output is correct |
10 |
Correct |
26 ms |
6236 KB |
Output is correct |
11 |
Correct |
147 ms |
31708 KB |
Output is correct |
12 |
Correct |
41 ms |
9040 KB |
Output is correct |
13 |
Correct |
108 ms |
23952 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
4 ms |
1216 KB |
Output is correct |
16 |
Correct |
437 ms |
55832 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
432 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1086 ms |
109900 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Runtime error |
7 ms |
3032 KB |
Execution killed with signal 6 |
27 |
Halted |
0 ms |
0 KB |
- |