#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define m_p make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
const int N = 200005;
int n;
vector<int> g[N];
bool c[N];
void dfs(int x)
{
c[x] = true;
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
if (c[h])
continue;
dfs(h);
}
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
std::vector<int> u, v, a, b;
n = sz(x);
vector<pair<int, int> > p;
map<pair<int, int>, int> mp;
for (int i = 0; i < n; ++i)
{
p.push_back(m_p(x[i], y[i]));
mp[m_p(x[i], y[i])] = i;
}
sort(all(p));
set<pair<int, int> > s;
for (int i = 0; i < n; ++i)
{
int x = p[i].fi;
int y = p[i].se;
if (mp.find(m_p(x + 2, y)) != mp.end())
{
u.push_back(mp[m_p(x, y)]);
v.push_back(mp[m_p(x + 2, y)]);
if (s.find(m_p(x + 1, y + 1)) == s.end())
{
a.push_back(x + 1);
b.push_back(y + 1);
}
else if (s.find(m_p(x + 1, y - 1)) == s.end())
{
a.push_back(x + 1);
b.push_back(y - 1);
}
else
{
assert(false);
}
s.insert(m_p(a.back(), b.back()));
g[u.back()].push_back(v.back());
g[v.back()].push_back(u.back());
}
if (mp.find(m_p(x, y + 2)) != mp.end())
{
u.push_back(mp[m_p(x, y)]);
v.push_back(mp[m_p(x, y + 2)]);
if (s.find(m_p(x + 1, y + 1)) == s.end())
{
a.push_back(x + 1);
b.push_back(y + 1);
}
else if (s.find(m_p(x - 1, y + 1)) == s.end())
{
a.push_back(x - 1);
b.push_back(y + 1);
}
else
{
assert(false);
}
s.insert(m_p(a.back(), b.back()));
g[u.back()].push_back(v.back());
g[v.back()].push_back(u.back());
}
}
dfs(0);
for (int i = 0; i < n; ++i)
{
if (!c[i])
return 0;
}
build(u, v, a, b);
return 1;
}
Compilation message
parks.cpp: In function 'void dfs(int)':
parks.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (int i = 0; i < g[x].size(); ++i)
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4988 KB |
Output is correct |
2 |
Correct |
2 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 |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
150 ms |
31116 KB |
Output is correct |
10 |
Correct |
13 ms |
7684 KB |
Output is correct |
11 |
Correct |
69 ms |
19172 KB |
Output is correct |
12 |
Correct |
18 ms |
9052 KB |
Output is correct |
13 |
Correct |
44 ms |
14456 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5332 KB |
Output is correct |
16 |
Correct |
183 ms |
29240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4988 KB |
Output is correct |
2 |
Correct |
2 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 |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
150 ms |
31116 KB |
Output is correct |
10 |
Correct |
13 ms |
7684 KB |
Output is correct |
11 |
Correct |
69 ms |
19172 KB |
Output is correct |
12 |
Correct |
18 ms |
9052 KB |
Output is correct |
13 |
Correct |
44 ms |
14456 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5332 KB |
Output is correct |
16 |
Correct |
183 ms |
29240 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4900 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
487 ms |
66296 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
5332 KB |
Output is correct |
26 |
Correct |
5 ms |
5704 KB |
Output is correct |
27 |
Correct |
6 ms |
5844 KB |
Output is correct |
28 |
Correct |
168 ms |
30544 KB |
Output is correct |
29 |
Correct |
241 ms |
42044 KB |
Output is correct |
30 |
Correct |
384 ms |
56708 KB |
Output is correct |
31 |
Correct |
524 ms |
65444 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
2 ms |
4948 KB |
Output is correct |
34 |
Correct |
2 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4948 KB |
Output is correct |
36 |
Correct |
2 ms |
4948 KB |
Output is correct |
37 |
Correct |
2 ms |
4948 KB |
Output is correct |
38 |
Correct |
2 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 |
5332 KB |
Output is correct |
44 |
Correct |
5 ms |
5520 KB |
Output is correct |
45 |
Correct |
165 ms |
29708 KB |
Output is correct |
46 |
Correct |
266 ms |
41564 KB |
Output is correct |
47 |
Correct |
285 ms |
41340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4988 KB |
Output is correct |
2 |
Correct |
2 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 |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
150 ms |
31116 KB |
Output is correct |
10 |
Correct |
13 ms |
7684 KB |
Output is correct |
11 |
Correct |
69 ms |
19172 KB |
Output is correct |
12 |
Correct |
18 ms |
9052 KB |
Output is correct |
13 |
Correct |
44 ms |
14456 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5332 KB |
Output is correct |
16 |
Correct |
183 ms |
29240 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4900 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
487 ms |
66296 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
5332 KB |
Output is correct |
26 |
Correct |
5 ms |
5704 KB |
Output is correct |
27 |
Correct |
6 ms |
5844 KB |
Output is correct |
28 |
Correct |
168 ms |
30544 KB |
Output is correct |
29 |
Correct |
241 ms |
42044 KB |
Output is correct |
30 |
Correct |
384 ms |
56708 KB |
Output is correct |
31 |
Correct |
524 ms |
65444 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
2 ms |
4948 KB |
Output is correct |
34 |
Correct |
2 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4948 KB |
Output is correct |
36 |
Correct |
2 ms |
4948 KB |
Output is correct |
37 |
Correct |
2 ms |
4948 KB |
Output is correct |
38 |
Correct |
2 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 |
5332 KB |
Output is correct |
44 |
Correct |
5 ms |
5520 KB |
Output is correct |
45 |
Correct |
165 ms |
29708 KB |
Output is correct |
46 |
Correct |
266 ms |
41564 KB |
Output is correct |
47 |
Correct |
285 ms |
41340 KB |
Output is correct |
48 |
Correct |
2 ms |
4948 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
50 |
Runtime error |
6 ms |
9940 KB |
Execution killed with signal 6 |
51 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4988 KB |
Output is correct |
2 |
Correct |
2 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 |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
150 ms |
31116 KB |
Output is correct |
10 |
Correct |
13 ms |
7684 KB |
Output is correct |
11 |
Correct |
69 ms |
19172 KB |
Output is correct |
12 |
Correct |
18 ms |
9052 KB |
Output is correct |
13 |
Correct |
44 ms |
14456 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5332 KB |
Output is correct |
16 |
Correct |
183 ms |
29240 KB |
Output is correct |
17 |
Correct |
2 ms |
4884 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
455 ms |
58852 KB |
Output is correct |
21 |
Correct |
425 ms |
56816 KB |
Output is correct |
22 |
Correct |
468 ms |
55752 KB |
Output is correct |
23 |
Correct |
362 ms |
47768 KB |
Output is correct |
24 |
Correct |
179 ms |
22096 KB |
Output is correct |
25 |
Correct |
339 ms |
41436 KB |
Output is correct |
26 |
Correct |
290 ms |
41444 KB |
Output is correct |
27 |
Runtime error |
137 ms |
44972 KB |
Execution killed with signal 6 |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4988 KB |
Output is correct |
2 |
Correct |
2 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 |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
150 ms |
31116 KB |
Output is correct |
10 |
Correct |
13 ms |
7684 KB |
Output is correct |
11 |
Correct |
69 ms |
19172 KB |
Output is correct |
12 |
Correct |
18 ms |
9052 KB |
Output is correct |
13 |
Correct |
44 ms |
14456 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5332 KB |
Output is correct |
16 |
Correct |
183 ms |
29240 KB |
Output is correct |
17 |
Correct |
372 ms |
58648 KB |
Output is correct |
18 |
Runtime error |
203 ms |
64132 KB |
Execution killed with signal 6 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4988 KB |
Output is correct |
2 |
Correct |
2 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 |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
150 ms |
31116 KB |
Output is correct |
10 |
Correct |
13 ms |
7684 KB |
Output is correct |
11 |
Correct |
69 ms |
19172 KB |
Output is correct |
12 |
Correct |
18 ms |
9052 KB |
Output is correct |
13 |
Correct |
44 ms |
14456 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5332 KB |
Output is correct |
16 |
Correct |
183 ms |
29240 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4900 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
487 ms |
66296 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
5332 KB |
Output is correct |
26 |
Correct |
5 ms |
5704 KB |
Output is correct |
27 |
Correct |
6 ms |
5844 KB |
Output is correct |
28 |
Correct |
168 ms |
30544 KB |
Output is correct |
29 |
Correct |
241 ms |
42044 KB |
Output is correct |
30 |
Correct |
384 ms |
56708 KB |
Output is correct |
31 |
Correct |
524 ms |
65444 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
2 ms |
4948 KB |
Output is correct |
34 |
Correct |
2 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4948 KB |
Output is correct |
36 |
Correct |
2 ms |
4948 KB |
Output is correct |
37 |
Correct |
2 ms |
4948 KB |
Output is correct |
38 |
Correct |
2 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 |
5332 KB |
Output is correct |
44 |
Correct |
5 ms |
5520 KB |
Output is correct |
45 |
Correct |
165 ms |
29708 KB |
Output is correct |
46 |
Correct |
266 ms |
41564 KB |
Output is correct |
47 |
Correct |
285 ms |
41340 KB |
Output is correct |
48 |
Correct |
2 ms |
4948 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
50 |
Runtime error |
6 ms |
9940 KB |
Execution killed with signal 6 |
51 |
Halted |
0 ms |
0 KB |
- |