#include <vector>
#include <map>
#include <queue>
using namespace std;
void build(std::vector<int> u, std::vector<int> v, std::vector<int> a, std::vector<int> b);
int construct_roads(std::vector<int> x, std::vector<int> y)
{
int n=x.size();
vector<int> u,v,a,b;
map<pair<int,int>,int> ind;
for(int i=0;i<n;i++)
ind[{x[i],y[i]}]=i;
map<int,bool> vis;
queue<pair<int,int>> q;
q.push({x[0],y[0]});
vis[0]=1;
while(q.size())
{
auto f=q.front();
q.pop();
if(ind.find({f.first,f.second+2})!=ind.end() and !vis[ind[{f.first,f.second+2}]])
{
vis[ind[{f.first,f.second+2}]]=1;
u.push_back(ind[f]);
v.push_back(ind[{f.first,f.second+2}]);
if(f.first==2)
{
a.push_back(f.first-1);
b.push_back(f.second+1);
}
else// 4
{
a.push_back(f.first+1);
b.push_back(f.second+1);
}
q.push({f.first,f.second+2});
}
if(ind.find({f.first+2,f.second})!=ind.end() and !vis[ind[{f.first+2,f.second}]])
{
vis[ind[{f.first+2,f.second}]]=1;
u.push_back(ind[f]);
v.push_back(ind[{f.first+2,f.second}]);
a.push_back(f.first+1);
b.push_back(f.second+1);
q.push({f.first+2,f.second});
}
if(ind.find({f.first,f.second-2})!=ind.end() and !vis[ind[{f.first,f.second-2}]])
{
vis[ind[{f.first,f.second-2}]]=1;
u.push_back(ind[f]);
v.push_back(ind[{f.first,f.second-2}]);
if(f.first==2)
{
a.push_back(f.first-1);
b.push_back(f.second-1);
}
else// 4
{
a.push_back(f.first+1);
b.push_back(f.second-1);
}
q.push({f.first,f.second-2});
}
if(ind.find({f.first-2,f.second})!=ind.end() and !vis[ind[{f.first-2,f.second}]])
{
vis[ind[{f.first-2,f.second}]]=1;
u.push_back(ind[f]);
v.push_back(ind[{f.first-2,f.second}]);
a.push_back(f.first-1);
b.push_back(f.second-1);
q.push({f.first-2,f.second});
}
}
if(vis.size()!=n)
return 0;
build(u,v,a,b);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:74:15: warning: comparison of integer expressions of different signedness: 'std::map<int, bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
74 | if(vis.size()!=n)
| ~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
172 ms |
17628 KB |
Output is correct |
10 |
Correct |
13 ms |
2140 KB |
Output is correct |
11 |
Correct |
81 ms |
9492 KB |
Output is correct |
12 |
Correct |
18 ms |
3164 KB |
Output is correct |
13 |
Correct |
41 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
171 ms |
17640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
172 ms |
17628 KB |
Output is correct |
10 |
Correct |
13 ms |
2140 KB |
Output is correct |
11 |
Correct |
81 ms |
9492 KB |
Output is correct |
12 |
Correct |
18 ms |
3164 KB |
Output is correct |
13 |
Correct |
41 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
171 ms |
17640 KB |
Output is correct |
17 |
Correct |
0 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 |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
456 ms |
34832 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
148 ms |
14140 KB |
Output is correct |
29 |
Correct |
241 ms |
20916 KB |
Output is correct |
30 |
Correct |
353 ms |
27832 KB |
Output is correct |
31 |
Correct |
435 ms |
34848 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
178 ms |
17440 KB |
Output is correct |
46 |
Correct |
274 ms |
25424 KB |
Output is correct |
47 |
Correct |
283 ms |
25784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
172 ms |
17628 KB |
Output is correct |
10 |
Correct |
13 ms |
2140 KB |
Output is correct |
11 |
Correct |
81 ms |
9492 KB |
Output is correct |
12 |
Correct |
18 ms |
3164 KB |
Output is correct |
13 |
Correct |
41 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
171 ms |
17640 KB |
Output is correct |
17 |
Correct |
0 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 |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
456 ms |
34832 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
148 ms |
14140 KB |
Output is correct |
29 |
Correct |
241 ms |
20916 KB |
Output is correct |
30 |
Correct |
353 ms |
27832 KB |
Output is correct |
31 |
Correct |
435 ms |
34848 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
178 ms |
17440 KB |
Output is correct |
46 |
Correct |
274 ms |
25424 KB |
Output is correct |
47 |
Correct |
283 ms |
25784 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Incorrect |
0 ms |
348 KB |
Tree @(5, 3) appears more than once: for edges on positions 1 and 3 |
52 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
172 ms |
17628 KB |
Output is correct |
10 |
Correct |
13 ms |
2140 KB |
Output is correct |
11 |
Correct |
81 ms |
9492 KB |
Output is correct |
12 |
Correct |
18 ms |
3164 KB |
Output is correct |
13 |
Correct |
41 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
171 ms |
17640 KB |
Output is correct |
17 |
Correct |
0 ms |
544 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Incorrect |
431 ms |
34972 KB |
Tree @(195233, 4771) appears more than once: for edges on positions 0 and 2 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
172 ms |
17628 KB |
Output is correct |
10 |
Correct |
13 ms |
2140 KB |
Output is correct |
11 |
Correct |
81 ms |
9492 KB |
Output is correct |
12 |
Correct |
18 ms |
3164 KB |
Output is correct |
13 |
Correct |
41 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
171 ms |
17640 KB |
Output is correct |
17 |
Correct |
426 ms |
34984 KB |
Output is correct |
18 |
Incorrect |
429 ms |
34724 KB |
Tree @(50003, 50003) appears more than once: for edges on positions 39328 and 39329 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
172 ms |
17628 KB |
Output is correct |
10 |
Correct |
13 ms |
2140 KB |
Output is correct |
11 |
Correct |
81 ms |
9492 KB |
Output is correct |
12 |
Correct |
18 ms |
3164 KB |
Output is correct |
13 |
Correct |
41 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
171 ms |
17640 KB |
Output is correct |
17 |
Correct |
0 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 |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
456 ms |
34832 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
148 ms |
14140 KB |
Output is correct |
29 |
Correct |
241 ms |
20916 KB |
Output is correct |
30 |
Correct |
353 ms |
27832 KB |
Output is correct |
31 |
Correct |
435 ms |
34848 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
178 ms |
17440 KB |
Output is correct |
46 |
Correct |
274 ms |
25424 KB |
Output is correct |
47 |
Correct |
283 ms |
25784 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Incorrect |
0 ms |
348 KB |
Tree @(5, 3) appears more than once: for edges on positions 1 and 3 |
52 |
Halted |
0 ms |
0 KB |
- |