#include <bits/stdc++.h>
#include "parks.h"
using namespace std;
void build(vector<int>u, vector<int>v, vector<int>a, vector<int>b);
int construct_roads(std::vector<int> xx, std::vector<int> yy) {
const int n = (int)xx.size();
set<pair<int,int>>s;
set<pair<int,int>>t;
map<pair<int,int>,int>id;
for(int i = 0 ; i < n ; i++)
s.insert({xx[i], yy[i]}), id[{xx[i], yy[i]}] = i;
int F,S;
for(int i = 0 ; i < n ; i++) {
if(!s.count({xx[i]-2, yy[i]}))
F = xx[i], S = yy[i];
}
queue<pair<pair<int,int>, int>>st;
st.push({{F, S}, 0});
s.erase(s.find({F, S}));
vector<int>u,v,a,b;
auto process = [&] (int X, int Y, int T) -> void {
s.erase(s.find({X,Y}));
u.push_back(id[{X,Y}]);
st.push({{X, Y}, T});
if(T == 0) {
v.push_back(id[{X-2,Y}]);
if(!t.count({X-1, Y+1}))
t.insert({X-1, Y+1}), a.push_back(X-1), b.push_back(Y+1);
else
t.insert({X-1, Y-1}), a.push_back(X-1), b.push_back(Y-1);
} else if(T == 1) {
v.push_back(id[{X,Y+2}]);
if(!t.count({X+1, Y+1}))
t.insert({X+1, Y+1}), a.push_back(X+1), b.push_back(Y+1);
else
t.insert({X-1, Y+1}), a.push_back(X-1), b.push_back(Y+1);
} else if(T == 2) {
v.push_back(id[{X+2,Y}]);
if(!t.count({X+1, Y-1}))
t.insert({X+1, Y-1}), a.push_back(X+1), b.push_back(Y-1);
else
t.insert({X+1, Y+1}), a.push_back(X+1), b.push_back(Y+1);
} else {
v.push_back(id[{X,Y-2}]);
if(t.count({X-1, Y-1}))
t.insert({X-1, Y-1}), a.push_back(X-1), b.push_back(Y-1);
else
t.insert({X+1, Y-1}), a.push_back(X+1), b.push_back(Y-1);
}
};
int cnt = 0;
while(!st.empty()) {
auto [x,y] = st.front().first;
int d = st.front().second;
st.pop();
cnt++;
if(d == 0) {
if(s.count({x, y+2})) {
process(x, y+2, 3);
if(s.count({x+2, y}))
process(x+2, y, 0);
if(s.count({x, y-2}))
process(x, y-2, 1);
} else {
if(s.count({x, y-2}))
process(x, y-2, 1);
if(s.count({x+2, y}))
process(x+2, y, 0);
}
} else if(d == 1) {
if(s.count({x+2, y})) {
process(x+2, y, 0);
if(s.count({x, y-2}))
process(x, y-2, 1);
if(s.count({x-2, y}))
process(x-2, y, 2);
} else {
if(s.count({x-2, y}))
process(x-2, y, 2);
if(s.count({x, y-2}))
process(x, y-2, 1);
}
} else if(d == 2) {
if(s.count({x, y-2})) {
process(x, y-2, 1);
if(s.count({x-2, y}))
process(x-2, y, 2);
if(s.count({x, y+2}))
process(x, y+2, 3);
} else {
if(s.count({x, y+2}))
process(x, y+2, 3);
if(s.count({x-2, y}))
process(x-2, y, 2);
}
} else {
if(s.count({x-2, y})) {
process(x-2, y, 2);
if(s.count({x, y+2}))
process(x, y+2, 3);
if(s.count({x+2, y}))
process(x+2, y, 0);
} else {
if(s.count({x+2, y}))
process(x+2, y, 0);
if(s.count({x, y+2}))
process(x, y+2, 3);
}
}
}
if(cnt < n)
return 0;
build(u,v,a,b);
return 1;
}
# |
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 |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
197 ms |
18468 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
85 ms |
10144 KB |
Output is correct |
12 |
Correct |
20 ms |
3204 KB |
Output is correct |
13 |
Correct |
36 ms |
6460 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
226 ms |
18452 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 |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
197 ms |
18468 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
85 ms |
10144 KB |
Output is correct |
12 |
Correct |
20 ms |
3204 KB |
Output is correct |
13 |
Correct |
36 ms |
6460 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
226 ms |
18452 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Incorrect |
593 ms |
36488 KB |
Tree @(3, 91603) appears more than once: for edges on positions 3 and 4 |
24 |
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 |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
197 ms |
18468 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
85 ms |
10144 KB |
Output is correct |
12 |
Correct |
20 ms |
3204 KB |
Output is correct |
13 |
Correct |
36 ms |
6460 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
226 ms |
18452 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Incorrect |
593 ms |
36488 KB |
Tree @(3, 91603) appears more than once: for edges on positions 3 and 4 |
24 |
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 |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
197 ms |
18468 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
85 ms |
10144 KB |
Output is correct |
12 |
Correct |
20 ms |
3204 KB |
Output is correct |
13 |
Correct |
36 ms |
6460 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
226 ms |
18452 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
Tree @(199999, 3) appears more than once: for edges on positions 0 and 1 |
18 |
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 |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
197 ms |
18468 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
85 ms |
10144 KB |
Output is correct |
12 |
Correct |
20 ms |
3204 KB |
Output is correct |
13 |
Correct |
36 ms |
6460 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
226 ms |
18452 KB |
Output is correct |
17 |
Incorrect |
586 ms |
36892 KB |
Tree @(100001, 3) appears more than once: for edges on positions 145133 and 145135 |
18 |
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 |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
197 ms |
18468 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
85 ms |
10144 KB |
Output is correct |
12 |
Correct |
20 ms |
3204 KB |
Output is correct |
13 |
Correct |
36 ms |
6460 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
226 ms |
18452 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Incorrect |
593 ms |
36488 KB |
Tree @(3, 91603) appears more than once: for edges on positions 3 and 4 |
24 |
Halted |
0 ms |
0 KB |
- |