#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
struct dsu {
vector<int> e;
int cc;
dsu(int n) {
cc=n;
e=vector<int> (n, -1);
}
int get(int a) {
if(e[a] < 0)return a;
return e[a] = get(e[a]);
}
bool unite(int a, int b) {
a=get(a), b=get(b);
if(a==b)return false;
cc--;
if(-e[a] > -e[b])swap(a, b);
e[b]+=e[a];
e[a]=b;
return true;
}
};
int construct_roads(std::vector<int> x, std::vector<int> y) {
vector<vector<int>> p(7);
int n = x.size();
map<pair<int,int>, int> mp;
for(int i = 0;i<n;i++) {
mp[{x[i], y[i]}]=i;
p[x[i]].push_back(i);
}
dsu d(n);
vector<int> u, v;
for(int i= 0;i<7;i++) {
sort(p[i].begin(), p[i].end(), [&](int a, int b) {
return y[a] < y[b];
});
}
{
int i = 6;
for(int j = 1;j<(int)p[i].size();j++) {
if(y[p[i][j]] == y[p[i][j-1]] + 2){
if(d.unite(p[i][j], p[i][j-1])) {
v.push_back(p[i][j]);
u.push_back(p[i][j-1]);
}
}
}
}
{
int i = 2;
for(int j = 1;j<(int)p[i].size();j++) {
if(y[p[i][j]] == y[p[i][j-1]] + 2){
if(d.unite(p[i][j], p[i][j-1])) {
v.push_back(p[i][j]);
u.push_back(p[i][j-1]);
}
}
}
}
{
int i = 4;
for(int j = 1;j<(int)p[i].size();j++) {
if(y[p[i][j]] == y[p[i][j-1]] + 2){
if(d.unite(p[i][j], p[i][j-1])) {
v.push_back(p[i][j]);
u.push_back(p[i][j-1]);
}
}
}
}
{
for(int j:p[4]) {
if(mp.find({x[j]-2, y[j]}) != mp.end() and d.unite(j, mp[{x[j]-2, y[j]}])) {
u.push_back(mp[{x[j]-2, y[j]}]);
v.push_back(j);
}
}
for(int j:p[4]) {
if(mp.find({x[j]+2, y[j]}) != mp.end() and d.unite(j, mp[{x[j]+2, y[j]}])) {
v.push_back(mp[{x[j]+2, y[j]}]);
u.push_back(j);
}
}
}
// for(int i = 0;i<(int)v.size();i++) {
// cout << u[i] << " "<< v[i] << endl;
// }
vector<int> a, b;
if(d.cc != 1)return 0;
map<pair<int,int>, bool> used;
for(int j = 0;j<n-1;j++) {
if(x[u[j]] == x[v[j]]) {
if(x[u[j]] == 2) {
a.push_back(x[u[j]]-1);
b.push_back(y[u[j]]+1);
used[{x[u[j]]-1,y[u[j]]+1}]=1;
}
else if(x[u[j]] == 6) {
a.push_back(x[u[j]]+1);
b.push_back(y[u[j]]+1);
used[{x[u[j]]+1,y[u[j]]+1}]=1;
}
else if(x[u[j]] == 4) {
a.push_back(-1);
b.push_back(-1);
}
}
else if(x[u[j]] == 2) {
a.push_back(x[u[j]]+1);
b.push_back(y[u[j]]+1);
used[{x[u[j]]+1, y[u[j]]+1}]=1;
} else if(x[u[j]] == 4) {
a.push_back(x[u[j]]+1);
b.push_back(y[u[j]]-1);
used[{x[u[j]]+1, y[u[j]]-1}]=1;
}
}
for(int j = 0;j<n-1;j++) {
if(a[j] == -1) {
if(!used[{x[u[j]]-1, y[u[j]]+1}]) {
a[j] = x[u[j]]-1;
b[j] = y[u[j]]+1;
used[{x[u[j]]-1, y[u[j]]+1}]=1;
}
else {
a[j] = x[u[j]]+1;
b[j] = y[u[j]]+1;
used[{x[u[j]]+1, y[u[j]]+1}]=1;
}
}
}
build(u, v, a, b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
92 ms |
20936 KB |
Output is correct |
10 |
Correct |
6 ms |
2652 KB |
Output is correct |
11 |
Correct |
45 ms |
11336 KB |
Output is correct |
12 |
Correct |
9 ms |
3676 KB |
Output is correct |
13 |
Correct |
13 ms |
5080 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
89 ms |
20852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
92 ms |
20936 KB |
Output is correct |
10 |
Correct |
6 ms |
2652 KB |
Output is correct |
11 |
Correct |
45 ms |
11336 KB |
Output is correct |
12 |
Correct |
9 ms |
3676 KB |
Output is correct |
13 |
Correct |
13 ms |
5080 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
89 ms |
20852 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
267 ms |
41024 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
748 KB |
Output is correct |
28 |
Correct |
75 ms |
16616 KB |
Output is correct |
29 |
Correct |
127 ms |
24812 KB |
Output is correct |
30 |
Correct |
178 ms |
33020 KB |
Output is correct |
31 |
Correct |
260 ms |
41008 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
122 ms |
20812 KB |
Output is correct |
46 |
Correct |
155 ms |
29920 KB |
Output is correct |
47 |
Correct |
174 ms |
29544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
92 ms |
20936 KB |
Output is correct |
10 |
Correct |
6 ms |
2652 KB |
Output is correct |
11 |
Correct |
45 ms |
11336 KB |
Output is correct |
12 |
Correct |
9 ms |
3676 KB |
Output is correct |
13 |
Correct |
13 ms |
5080 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
89 ms |
20852 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
267 ms |
41024 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
748 KB |
Output is correct |
28 |
Correct |
75 ms |
16616 KB |
Output is correct |
29 |
Correct |
127 ms |
24812 KB |
Output is correct |
30 |
Correct |
178 ms |
33020 KB |
Output is correct |
31 |
Correct |
260 ms |
41008 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
122 ms |
20812 KB |
Output is correct |
46 |
Correct |
155 ms |
29920 KB |
Output is correct |
47 |
Correct |
174 ms |
29544 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
344 KB |
Output is correct |
51 |
Incorrect |
0 ms |
348 KB |
Tree @(5, 3) appears more than once: for edges on positions 2 and 5 |
52 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
92 ms |
20936 KB |
Output is correct |
10 |
Correct |
6 ms |
2652 KB |
Output is correct |
11 |
Correct |
45 ms |
11336 KB |
Output is correct |
12 |
Correct |
9 ms |
3676 KB |
Output is correct |
13 |
Correct |
13 ms |
5080 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
89 ms |
20852 KB |
Output is correct |
17 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
92 ms |
20936 KB |
Output is correct |
10 |
Correct |
6 ms |
2652 KB |
Output is correct |
11 |
Correct |
45 ms |
11336 KB |
Output is correct |
12 |
Correct |
9 ms |
3676 KB |
Output is correct |
13 |
Correct |
13 ms |
5080 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
89 ms |
20852 KB |
Output is correct |
17 |
Runtime error |
28 ms |
8784 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
92 ms |
20936 KB |
Output is correct |
10 |
Correct |
6 ms |
2652 KB |
Output is correct |
11 |
Correct |
45 ms |
11336 KB |
Output is correct |
12 |
Correct |
9 ms |
3676 KB |
Output is correct |
13 |
Correct |
13 ms |
5080 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
89 ms |
20852 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
267 ms |
41024 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
748 KB |
Output is correct |
28 |
Correct |
75 ms |
16616 KB |
Output is correct |
29 |
Correct |
127 ms |
24812 KB |
Output is correct |
30 |
Correct |
178 ms |
33020 KB |
Output is correct |
31 |
Correct |
260 ms |
41008 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
122 ms |
20812 KB |
Output is correct |
46 |
Correct |
155 ms |
29920 KB |
Output is correct |
47 |
Correct |
174 ms |
29544 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
344 KB |
Output is correct |
51 |
Incorrect |
0 ms |
348 KB |
Tree @(5, 3) appears more than once: for edges on positions 2 and 5 |
52 |
Halted |
0 ms |
0 KB |
- |