#include "parks.h"
#include <map>
#include <utility>
#include <queue>
using namespace std;
map < pair < int , int > , int > all,con;
map < pair < int , int > , pair < int , int > > road;
vector < int > u,v,a,b;
queue < pair < int , int > > BFS;
int Father[200005];
int Find(int here)
{
if(Father[here]==here) return here;
Father[here]=Find(Father[here]);
return Father[here];
}
int construct_roads(vector < int > x, vector < int > y)
{
int N=x.size(),i,t,aa,bb,ok=1,xx,yy;
for(i=0;i<N;i++)
{
all[make_pair(x[i],y[i])]=i;
Father[i]=i;
}
for(i=0;i<N;i++)
{
if(all.find(make_pair(x[i],y[i]+2))!=all.end())
{
t=all[make_pair(x[i],y[i]+2)];
road[make_pair(x[i],y[i]+1)]=make_pair(i,t);
con[make_pair(x[i]+1,y[i]+1)]++;
con[make_pair(x[i]-1,y[i]+1)]++;
aa=Find(i);
bb=Find(t);
if(aa!=bb) Father[aa]=bb;
}
if(all.find(make_pair(x[i]+2,y[i]))!=all.end())
{
t=all[make_pair(x[i]+2,y[i])];
road[make_pair(x[i]+1,y[i])]=make_pair(i,t);
con[make_pair(x[i]+1,y[i]+1)]++;
con[make_pair(x[i]+1,y[i]-1)]++;
aa=Find(i);
bb=Find(t);
if(aa!=bb) Father[aa]=bb;
}
}
t=Find(0);
for(i=0;i<N;i++) if(t!=Find(i)) ok=0;
if(ok==0) return ok;
for(auto i:con) if(i.second==1) BFS.push(i.first);
while(!BFS.empty())
{
xx=BFS.front().first;
yy=BFS.front().second;
BFS.pop();
if(con[make_pair(xx,yy)]==0) continue;
if(road.find(make_pair(xx+1,yy))!=road.end()) aa=xx+1,bb=yy;
if(road.find(make_pair(xx-1,yy))!=road.end()) aa=xx-1,bb=yy;
if(road.find(make_pair(xx,yy+1))!=road.end()) aa=xx,bb=yy+1;
if(road.find(make_pair(xx,yy-1))!=road.end()) aa=xx,bb=yy-1;
u.push_back(road[make_pair(aa,bb)].first);
v.push_back(road[make_pair(aa,bb)].second);
a.push_back(xx);
b.push_back(yy);
road.erase(make_pair(aa,bb));
if(aa%2==0)
{
con[make_pair(aa-1,bb)]--;
con[make_pair(aa+1,bb)]--;
if(con[make_pair(aa-1,bb)]==1) BFS.push(make_pair(aa-1,bb));
if(con[make_pair(aa+1,bb)]==1) BFS.push(make_pair(aa+1,bb));
}
else
{
con[make_pair(aa,bb-1)]--;
con[make_pair(aa,bb+1)]--;
if(con[make_pair(aa,bb-1)]==1) BFS.push(make_pair(aa,bb-1));
if(con[make_pair(aa,bb+1)]==1) BFS.push(make_pair(aa,bb+1));
}
}
if(ok) build(u,v,a,b);
return ok;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:80:32: warning: 'bb' may be used uninitialized in this function [-Wmaybe-uninitialized]
80 | con[make_pair(aa,bb+1)]--;
| ~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
441 ms |
33192 KB |
Output is correct |
10 |
Correct |
27 ms |
3824 KB |
Output is correct |
11 |
Correct |
180 ms |
18848 KB |
Output is correct |
12 |
Correct |
42 ms |
5580 KB |
Output is correct |
13 |
Correct |
77 ms |
12560 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
3 ms |
716 KB |
Output is correct |
16 |
Correct |
437 ms |
32976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
441 ms |
33192 KB |
Output is correct |
10 |
Correct |
27 ms |
3824 KB |
Output is correct |
11 |
Correct |
180 ms |
18848 KB |
Output is correct |
12 |
Correct |
42 ms |
5580 KB |
Output is correct |
13 |
Correct |
77 ms |
12560 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
3 ms |
716 KB |
Output is correct |
16 |
Correct |
437 ms |
32976 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1469 ms |
70316 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
4 ms |
716 KB |
Output is correct |
26 |
Correct |
6 ms |
972 KB |
Output is correct |
27 |
Correct |
8 ms |
1356 KB |
Output is correct |
28 |
Correct |
454 ms |
28284 KB |
Output is correct |
29 |
Correct |
725 ms |
42324 KB |
Output is correct |
30 |
Correct |
1071 ms |
56320 KB |
Output is correct |
31 |
Correct |
1365 ms |
70500 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
3 ms |
716 KB |
Output is correct |
44 |
Correct |
6 ms |
972 KB |
Output is correct |
45 |
Correct |
491 ms |
28856 KB |
Output is correct |
46 |
Correct |
777 ms |
41828 KB |
Output is correct |
47 |
Correct |
784 ms |
41636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
441 ms |
33192 KB |
Output is correct |
10 |
Correct |
27 ms |
3824 KB |
Output is correct |
11 |
Correct |
180 ms |
18848 KB |
Output is correct |
12 |
Correct |
42 ms |
5580 KB |
Output is correct |
13 |
Correct |
77 ms |
12560 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
3 ms |
716 KB |
Output is correct |
16 |
Correct |
437 ms |
32976 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1469 ms |
70316 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
4 ms |
716 KB |
Output is correct |
26 |
Correct |
6 ms |
972 KB |
Output is correct |
27 |
Correct |
8 ms |
1356 KB |
Output is correct |
28 |
Correct |
454 ms |
28284 KB |
Output is correct |
29 |
Correct |
725 ms |
42324 KB |
Output is correct |
30 |
Correct |
1071 ms |
56320 KB |
Output is correct |
31 |
Correct |
1365 ms |
70500 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
3 ms |
716 KB |
Output is correct |
44 |
Correct |
6 ms |
972 KB |
Output is correct |
45 |
Correct |
491 ms |
28856 KB |
Output is correct |
46 |
Correct |
777 ms |
41828 KB |
Output is correct |
47 |
Correct |
784 ms |
41636 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
0 ms |
204 KB |
Output is correct |
50 |
Correct |
0 ms |
204 KB |
Output is correct |
51 |
Incorrect |
0 ms |
204 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
52 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
441 ms |
33192 KB |
Output is correct |
10 |
Correct |
27 ms |
3824 KB |
Output is correct |
11 |
Correct |
180 ms |
18848 KB |
Output is correct |
12 |
Correct |
42 ms |
5580 KB |
Output is correct |
13 |
Correct |
77 ms |
12560 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
3 ms |
716 KB |
Output is correct |
16 |
Correct |
437 ms |
32976 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
997 ms |
51684 KB |
Output is correct |
21 |
Correct |
1150 ms |
51648 KB |
Output is correct |
22 |
Correct |
1068 ms |
51572 KB |
Output is correct |
23 |
Correct |
878 ms |
56468 KB |
Output is correct |
24 |
Correct |
316 ms |
16712 KB |
Output is correct |
25 |
Correct |
871 ms |
54196 KB |
Output is correct |
26 |
Correct |
834 ms |
54192 KB |
Output is correct |
27 |
Correct |
1179 ms |
67348 KB |
Output is correct |
28 |
Correct |
1082 ms |
67020 KB |
Output is correct |
29 |
Correct |
1134 ms |
66512 KB |
Output is correct |
30 |
Correct |
1219 ms |
66640 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Incorrect |
59 ms |
4408 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
441 ms |
33192 KB |
Output is correct |
10 |
Correct |
27 ms |
3824 KB |
Output is correct |
11 |
Correct |
180 ms |
18848 KB |
Output is correct |
12 |
Correct |
42 ms |
5580 KB |
Output is correct |
13 |
Correct |
77 ms |
12560 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
3 ms |
716 KB |
Output is correct |
16 |
Correct |
437 ms |
32976 KB |
Output is correct |
17 |
Correct |
1087 ms |
67144 KB |
Output is correct |
18 |
Incorrect |
1063 ms |
67148 KB |
Given structure is not connected: There is no path between vertices 0 and 4 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
441 ms |
33192 KB |
Output is correct |
10 |
Correct |
27 ms |
3824 KB |
Output is correct |
11 |
Correct |
180 ms |
18848 KB |
Output is correct |
12 |
Correct |
42 ms |
5580 KB |
Output is correct |
13 |
Correct |
77 ms |
12560 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
3 ms |
716 KB |
Output is correct |
16 |
Correct |
437 ms |
32976 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1469 ms |
70316 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
4 ms |
716 KB |
Output is correct |
26 |
Correct |
6 ms |
972 KB |
Output is correct |
27 |
Correct |
8 ms |
1356 KB |
Output is correct |
28 |
Correct |
454 ms |
28284 KB |
Output is correct |
29 |
Correct |
725 ms |
42324 KB |
Output is correct |
30 |
Correct |
1071 ms |
56320 KB |
Output is correct |
31 |
Correct |
1365 ms |
70500 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
3 ms |
716 KB |
Output is correct |
44 |
Correct |
6 ms |
972 KB |
Output is correct |
45 |
Correct |
491 ms |
28856 KB |
Output is correct |
46 |
Correct |
777 ms |
41828 KB |
Output is correct |
47 |
Correct |
784 ms |
41636 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
0 ms |
204 KB |
Output is correct |
50 |
Correct |
0 ms |
204 KB |
Output is correct |
51 |
Incorrect |
0 ms |
204 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
52 |
Halted |
0 ms |
0 KB |
- |