#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN=2e5+6;
vector<int>g[MAXN];
map<pair<int,int>,int> tochki;
bool vis[MAXN];
vector<pair<int,int> >roads;
int cnt;
void dfs(int u)
{
vis[u]=1;
cnt++;
for(auto xd:g[u])
{
if(vis[xd])continue;
dfs(xd);
roads.push_back({u,xd});
}
}
int construct_roads(vector<int> x, vector<int> y) {
if (x.size() == 1) {
build({}, {}, {}, {});
return 1;
}
for(int i=0;i<x.size();i++)
{
tochki[make_pair(x[i],y[i])]=i;
}
for(int i=0;i<x.size();i++)
{
if(tochki.count(make_pair(x[i],y[i]-2)))
{
g[i].push_back(tochki[make_pair(x[i],y[i]-2)]);
}
if(tochki.count(make_pair(x[i],y[i]+2)))
{
g[i].push_back(tochki[make_pair(x[i],y[i]+2)]);
}
if(tochki.count(make_pair(x[i]+2,y[i])))
{
g[i].push_back(tochki[make_pair(x[i]+2,y[i])]);
}
if(tochki.count(make_pair(x[i]-2,y[i])))
{
g[i].push_back(tochki[make_pair(x[i]-2,y[i])]);
}
}
dfs(0);
if(cnt!=x.size())return 0;
vector<int>u;
vector<int>v;
vector<int>a;
vector<int>b;
for(int i=0;i<roads.size();i++)
{
u.push_back(roads[i].first);
v.push_back(roads[i].second);
if(x[roads[i].first]==x[roads[i].second])
{
int x1=x[roads[i].first];
int y1=min(y[roads[i].first],y[roads[i].second]);
if((x1+y1)%4==0)
{
a.push_back(x1+1);
b.push_back(y1+1);
}
else
{
a.push_back(x1-1);
b.push_back(y1+1);
}
}
else
{
int y1=y[roads[i].first];
int x1=min(x[roads[i].first],x[roads[i].second]);
if((x1+y1)%4==0)
{
a.push_back(x1+1);
b.push_back(y1-1);
}
else
{
a.push_back(x1+1);
b.push_back(y1+1);
}
}
}
build(u,v,a,b);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i=0;i<x.size();i++)
| ~^~~~~~~~~
parks.cpp:30:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=0;i<x.size();i++)
| ~^~~~~~~~~
parks.cpp:50:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | if(cnt!=x.size())return 0;
| ~~~^~~~~~~~~~
parks.cpp:55:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i=0;i<roads.size();i++)
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
5052 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
5168 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
147 ms |
31140 KB |
Output is correct |
10 |
Correct |
11 ms |
7884 KB |
Output is correct |
11 |
Correct |
69 ms |
19752 KB |
Output is correct |
12 |
Correct |
16 ms |
9048 KB |
Output is correct |
13 |
Correct |
39 ms |
13132 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5212 KB |
Output is correct |
16 |
Correct |
148 ms |
28044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
5052 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
5168 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
147 ms |
31140 KB |
Output is correct |
10 |
Correct |
11 ms |
7884 KB |
Output is correct |
11 |
Correct |
69 ms |
19752 KB |
Output is correct |
12 |
Correct |
16 ms |
9048 KB |
Output is correct |
13 |
Correct |
39 ms |
13132 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5212 KB |
Output is correct |
16 |
Correct |
148 ms |
28044 KB |
Output is correct |
17 |
Incorrect |
2 ms |
4956 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
5052 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
5168 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
147 ms |
31140 KB |
Output is correct |
10 |
Correct |
11 ms |
7884 KB |
Output is correct |
11 |
Correct |
69 ms |
19752 KB |
Output is correct |
12 |
Correct |
16 ms |
9048 KB |
Output is correct |
13 |
Correct |
39 ms |
13132 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5212 KB |
Output is correct |
16 |
Correct |
148 ms |
28044 KB |
Output is correct |
17 |
Incorrect |
2 ms |
4956 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
5052 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
5168 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
147 ms |
31140 KB |
Output is correct |
10 |
Correct |
11 ms |
7884 KB |
Output is correct |
11 |
Correct |
69 ms |
19752 KB |
Output is correct |
12 |
Correct |
16 ms |
9048 KB |
Output is correct |
13 |
Correct |
39 ms |
13132 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5212 KB |
Output is correct |
16 |
Correct |
148 ms |
28044 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
413 ms |
59320 KB |
Output is correct |
21 |
Correct |
421 ms |
55716 KB |
Output is correct |
22 |
Correct |
416 ms |
54016 KB |
Output is correct |
23 |
Correct |
336 ms |
46368 KB |
Output is correct |
24 |
Correct |
255 ms |
21832 KB |
Output is correct |
25 |
Correct |
349 ms |
28188 KB |
Output is correct |
26 |
Correct |
337 ms |
28244 KB |
Output is correct |
27 |
Correct |
414 ms |
42728 KB |
Output is correct |
28 |
Correct |
425 ms |
42616 KB |
Output is correct |
29 |
Correct |
463 ms |
42696 KB |
Output is correct |
30 |
Correct |
429 ms |
42656 KB |
Output is correct |
31 |
Correct |
1 ms |
4956 KB |
Output is correct |
32 |
Correct |
24 ms |
8456 KB |
Output is correct |
33 |
Correct |
88 ms |
13748 KB |
Output is correct |
34 |
Correct |
417 ms |
56776 KB |
Output is correct |
35 |
Correct |
12 ms |
6492 KB |
Output is correct |
36 |
Correct |
69 ms |
11208 KB |
Output is correct |
37 |
Correct |
148 ms |
17080 KB |
Output is correct |
38 |
Correct |
148 ms |
21032 KB |
Output is correct |
39 |
Correct |
230 ms |
26432 KB |
Output is correct |
40 |
Correct |
297 ms |
33148 KB |
Output is correct |
41 |
Correct |
380 ms |
38736 KB |
Output is correct |
42 |
Correct |
503 ms |
44524 KB |
Output is correct |
43 |
Correct |
2 ms |
4956 KB |
Output is correct |
44 |
Correct |
1 ms |
5172 KB |
Output is correct |
45 |
Correct |
2 ms |
4956 KB |
Output is correct |
46 |
Correct |
1 ms |
4956 KB |
Output is correct |
47 |
Correct |
1 ms |
4956 KB |
Output is correct |
48 |
Correct |
2 ms |
4956 KB |
Output is correct |
49 |
Correct |
1 ms |
5164 KB |
Output is correct |
50 |
Correct |
2 ms |
4956 KB |
Output is correct |
51 |
Correct |
2 ms |
4956 KB |
Output is correct |
52 |
Correct |
2 ms |
4956 KB |
Output is correct |
53 |
Correct |
2 ms |
4956 KB |
Output is correct |
54 |
Correct |
3 ms |
5432 KB |
Output is correct |
55 |
Correct |
4 ms |
5468 KB |
Output is correct |
56 |
Correct |
167 ms |
28852 KB |
Output is correct |
57 |
Correct |
282 ms |
40592 KB |
Output is correct |
58 |
Correct |
281 ms |
40012 KB |
Output is correct |
59 |
Correct |
2 ms |
4956 KB |
Output is correct |
60 |
Correct |
2 ms |
4956 KB |
Output is correct |
61 |
Correct |
1 ms |
4956 KB |
Output is correct |
62 |
Correct |
401 ms |
53680 KB |
Output is correct |
63 |
Correct |
346 ms |
53920 KB |
Output is correct |
64 |
Correct |
379 ms |
55544 KB |
Output is correct |
65 |
Correct |
5 ms |
5724 KB |
Output is correct |
66 |
Correct |
9 ms |
6024 KB |
Output is correct |
67 |
Correct |
174 ms |
26768 KB |
Output is correct |
68 |
Correct |
275 ms |
39684 KB |
Output is correct |
69 |
Correct |
417 ms |
47848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
5052 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
5168 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
147 ms |
31140 KB |
Output is correct |
10 |
Correct |
11 ms |
7884 KB |
Output is correct |
11 |
Correct |
69 ms |
19752 KB |
Output is correct |
12 |
Correct |
16 ms |
9048 KB |
Output is correct |
13 |
Correct |
39 ms |
13132 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5212 KB |
Output is correct |
16 |
Correct |
148 ms |
28044 KB |
Output is correct |
17 |
Correct |
377 ms |
59104 KB |
Output is correct |
18 |
Correct |
380 ms |
52900 KB |
Output is correct |
19 |
Correct |
423 ms |
59340 KB |
Output is correct |
20 |
Correct |
476 ms |
49536 KB |
Output is correct |
21 |
Correct |
390 ms |
44040 KB |
Output is correct |
22 |
Correct |
1 ms |
4956 KB |
Output is correct |
23 |
Correct |
51 ms |
11836 KB |
Output is correct |
24 |
Correct |
27 ms |
8020 KB |
Output is correct |
25 |
Correct |
131 ms |
13984 KB |
Output is correct |
26 |
Correct |
189 ms |
19844 KB |
Output is correct |
27 |
Correct |
193 ms |
27928 KB |
Output is correct |
28 |
Correct |
262 ms |
33524 KB |
Output is correct |
29 |
Correct |
327 ms |
39212 KB |
Output is correct |
30 |
Correct |
382 ms |
45160 KB |
Output is correct |
31 |
Correct |
503 ms |
48920 KB |
Output is correct |
32 |
Correct |
433 ms |
54968 KB |
Output is correct |
33 |
Correct |
383 ms |
58280 KB |
Output is correct |
34 |
Correct |
6 ms |
5720 KB |
Output is correct |
35 |
Correct |
10 ms |
6392 KB |
Output is correct |
36 |
Correct |
168 ms |
27064 KB |
Output is correct |
37 |
Correct |
290 ms |
39332 KB |
Output is correct |
38 |
Correct |
420 ms |
49708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
5052 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
5168 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
147 ms |
31140 KB |
Output is correct |
10 |
Correct |
11 ms |
7884 KB |
Output is correct |
11 |
Correct |
69 ms |
19752 KB |
Output is correct |
12 |
Correct |
16 ms |
9048 KB |
Output is correct |
13 |
Correct |
39 ms |
13132 KB |
Output is correct |
14 |
Correct |
2 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
5212 KB |
Output is correct |
16 |
Correct |
148 ms |
28044 KB |
Output is correct |
17 |
Incorrect |
2 ms |
4956 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |