#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200005], X, Y, U, V, A, B;
vector<pair<int, int> > edge;
map<pair<int, int>, bool> mp;
map<pair<int, int>, int> p;
bool visited[200005];
queue<int> q;
bool cmp(pair<int, int> u, pair<int, int> v)
{
if (X[u.first]!=X[v.first] || X[u.second]!=X[v.second])
return (X[u.first]<X[v.first] || X[u.second]<X[v.second]);
return Y[u.first]<Y[v.first];
}
int construct_roads(vector<int> x, vector<int> y)
{
int N=x.size();
for (int i=0; i<N; i++)
{
X.push_back(x[i]);
Y.push_back(y[i]);
p[{X[i], Y[i]}]=i+1;
}
for (auto itr=p.begin(); itr!=p.end(); itr++)
{
int ind=itr->second-1;
if (p[{X[ind]-2, Y[ind]}])
edge.push_back({p[{X[ind]-2, Y[ind]}]-1, ind});
if (p[{X[ind], Y[ind]-2}])
edge.push_back({p[{X[ind], Y[ind]-2}]-1, ind});
}
sort(edge.begin(), edge.end(), cmp);
for (int i=0; i<edge.size(); i++)
{
int u=edge[i].first, v=edge[i].second;
adj[u].push_back(v);
adj[v].push_back(u);
U.push_back(u);
V.push_back(v);
if (X[u]==X[v])
{
if (mp[{X[u]-1, Y[u]+1}])
{
A.push_back(X[u]+1);
B.push_back(Y[u]+1);
mp[{X[u]+1, Y[u]+1}]=1;
}
else
{
A.push_back(X[u]-1);
B.push_back(Y[u]+1);
mp[{X[u]-1, Y[u]+1}]=1;
}
}
else
{
if (mp[{X[u]+1, Y[u]-1}])
{
A.push_back(X[u]+1);
B.push_back(Y[u]+1);
mp[{X[u]+1, Y[u]+1}]=1;
}
else
{
A.push_back(X[u]+1);
B.push_back(Y[u]-1);
mp[{X[u]+1, Y[u]-1}]=1;
}
}
}
q.push(0);
visited[0]=1;
while (!q.empty())
{
int u=q.front();
q.pop();
for (int v:adj[u])
{
if (!visited[v])
{
q.push(v);
visited[v]=1;
}
}
}
for (int i=0; i<N; i++)
if (!visited[i])
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:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i=0; i<edge.size(); i++)
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
222 ms |
36152 KB |
Output is correct |
10 |
Correct |
16 ms |
8148 KB |
Output is correct |
11 |
Correct |
92 ms |
21712 KB |
Output is correct |
12 |
Correct |
24 ms |
9676 KB |
Output is correct |
13 |
Correct |
62 ms |
16828 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
5 ms |
5492 KB |
Output is correct |
16 |
Correct |
211 ms |
36148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
222 ms |
36152 KB |
Output is correct |
10 |
Correct |
16 ms |
8148 KB |
Output is correct |
11 |
Correct |
92 ms |
21712 KB |
Output is correct |
12 |
Correct |
24 ms |
9676 KB |
Output is correct |
13 |
Correct |
62 ms |
16828 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
5 ms |
5492 KB |
Output is correct |
16 |
Correct |
211 ms |
36148 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4896 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4920 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
588 ms |
76012 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
5332 KB |
Output is correct |
26 |
Correct |
6 ms |
5840 KB |
Output is correct |
27 |
Correct |
7 ms |
6100 KB |
Output is correct |
28 |
Correct |
202 ms |
32880 KB |
Output is correct |
29 |
Correct |
321 ms |
47200 KB |
Output is correct |
30 |
Correct |
440 ms |
61156 KB |
Output is correct |
31 |
Correct |
574 ms |
75984 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
2 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
2 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
2 ms |
4948 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
4 ms |
5460 KB |
Output is correct |
44 |
Correct |
5 ms |
5716 KB |
Output is correct |
45 |
Correct |
199 ms |
35196 KB |
Output is correct |
46 |
Correct |
303 ms |
49212 KB |
Output is correct |
47 |
Correct |
319 ms |
49192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
222 ms |
36152 KB |
Output is correct |
10 |
Correct |
16 ms |
8148 KB |
Output is correct |
11 |
Correct |
92 ms |
21712 KB |
Output is correct |
12 |
Correct |
24 ms |
9676 KB |
Output is correct |
13 |
Correct |
62 ms |
16828 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
5 ms |
5492 KB |
Output is correct |
16 |
Correct |
211 ms |
36148 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4896 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4920 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
588 ms |
76012 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
5332 KB |
Output is correct |
26 |
Correct |
6 ms |
5840 KB |
Output is correct |
27 |
Correct |
7 ms |
6100 KB |
Output is correct |
28 |
Correct |
202 ms |
32880 KB |
Output is correct |
29 |
Correct |
321 ms |
47200 KB |
Output is correct |
30 |
Correct |
440 ms |
61156 KB |
Output is correct |
31 |
Correct |
574 ms |
75984 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
2 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
2 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
2 ms |
4948 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
4 ms |
5460 KB |
Output is correct |
44 |
Correct |
5 ms |
5716 KB |
Output is correct |
45 |
Correct |
199 ms |
35196 KB |
Output is correct |
46 |
Correct |
303 ms |
49212 KB |
Output is correct |
47 |
Correct |
319 ms |
49192 KB |
Output is correct |
48 |
Correct |
3 ms |
4948 KB |
Output is correct |
49 |
Correct |
2 ms |
5004 KB |
Output is correct |
50 |
Correct |
3 ms |
4948 KB |
Output is correct |
51 |
Correct |
3 ms |
4948 KB |
Output is correct |
52 |
Correct |
3 ms |
4948 KB |
Output is correct |
53 |
Incorrect |
2 ms |
4948 KB |
Tree @(5, 5) appears more than once: for edges on positions 4 and 6 |
54 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
222 ms |
36152 KB |
Output is correct |
10 |
Correct |
16 ms |
8148 KB |
Output is correct |
11 |
Correct |
92 ms |
21712 KB |
Output is correct |
12 |
Correct |
24 ms |
9676 KB |
Output is correct |
13 |
Correct |
62 ms |
16828 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
5 ms |
5492 KB |
Output is correct |
16 |
Correct |
211 ms |
36148 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
447 ms |
62236 KB |
Output is correct |
21 |
Correct |
485 ms |
70620 KB |
Output is correct |
22 |
Correct |
460 ms |
64316 KB |
Output is correct |
23 |
Correct |
384 ms |
60436 KB |
Output is correct |
24 |
Correct |
243 ms |
48912 KB |
Output is correct |
25 |
Correct |
388 ms |
60216 KB |
Output is correct |
26 |
Correct |
368 ms |
60228 KB |
Output is correct |
27 |
Correct |
482 ms |
69152 KB |
Output is correct |
28 |
Correct |
497 ms |
69152 KB |
Output is correct |
29 |
Correct |
497 ms |
69268 KB |
Output is correct |
30 |
Correct |
483 ms |
69316 KB |
Output is correct |
31 |
Correct |
3 ms |
4948 KB |
Output is correct |
32 |
Incorrect |
31 ms |
9436 KB |
Tree @(185725, 20413) appears more than once: for edges on positions 631 and 647 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
222 ms |
36152 KB |
Output is correct |
10 |
Correct |
16 ms |
8148 KB |
Output is correct |
11 |
Correct |
92 ms |
21712 KB |
Output is correct |
12 |
Correct |
24 ms |
9676 KB |
Output is correct |
13 |
Correct |
62 ms |
16828 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
5 ms |
5492 KB |
Output is correct |
16 |
Correct |
211 ms |
36148 KB |
Output is correct |
17 |
Correct |
468 ms |
68060 KB |
Output is correct |
18 |
Correct |
467 ms |
70328 KB |
Output is correct |
19 |
Incorrect |
465 ms |
67416 KB |
Tree @(100001, 50003) appears more than once: for edges on positions 199994 and 199995 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
222 ms |
36152 KB |
Output is correct |
10 |
Correct |
16 ms |
8148 KB |
Output is correct |
11 |
Correct |
92 ms |
21712 KB |
Output is correct |
12 |
Correct |
24 ms |
9676 KB |
Output is correct |
13 |
Correct |
62 ms |
16828 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
5 ms |
5492 KB |
Output is correct |
16 |
Correct |
211 ms |
36148 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4896 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4920 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
588 ms |
76012 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
5332 KB |
Output is correct |
26 |
Correct |
6 ms |
5840 KB |
Output is correct |
27 |
Correct |
7 ms |
6100 KB |
Output is correct |
28 |
Correct |
202 ms |
32880 KB |
Output is correct |
29 |
Correct |
321 ms |
47200 KB |
Output is correct |
30 |
Correct |
440 ms |
61156 KB |
Output is correct |
31 |
Correct |
574 ms |
75984 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
2 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
2 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
2 ms |
4948 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
4 ms |
5460 KB |
Output is correct |
44 |
Correct |
5 ms |
5716 KB |
Output is correct |
45 |
Correct |
199 ms |
35196 KB |
Output is correct |
46 |
Correct |
303 ms |
49212 KB |
Output is correct |
47 |
Correct |
319 ms |
49192 KB |
Output is correct |
48 |
Correct |
3 ms |
4948 KB |
Output is correct |
49 |
Correct |
2 ms |
5004 KB |
Output is correct |
50 |
Correct |
3 ms |
4948 KB |
Output is correct |
51 |
Correct |
3 ms |
4948 KB |
Output is correct |
52 |
Correct |
3 ms |
4948 KB |
Output is correct |
53 |
Incorrect |
2 ms |
4948 KB |
Tree @(5, 5) appears more than once: for edges on positions 4 and 6 |
54 |
Halted |
0 ms |
0 KB |
- |