#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]}]=1;
map<int,bool> vis;
queue<pair<int,int>> q;
q.push({x[0],y[0]});
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(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:47:15: warning: comparison of integer expressions of different signedness: 'std::map<int, bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
47 | if(vis.size()!=n)
| ~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
Solution announced impossible, but it is possible. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
Solution announced impossible, but it is possible. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
Solution announced impossible, but it is possible. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
Solution announced impossible, but it is possible. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
Solution announced impossible, but it is possible. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
Solution announced impossible, but it is possible. |
2 |
Halted |
0 ms |
0 KB |
- |