#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 = 400005;
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);
}
}
vector<pair<int, int> > rs;
vector<int> gg[N], gi[N];
void dfs(int x, vector<int>& a, vector<int>& b)
{
c[x] = true;
for (int i = 0; i < gg[x].size(); ++i)
{
int h = gg[x][i];
if (a[gi[x][i]] == -1)
{
a[gi[x][i]] = rs[x].fi;
b[gi[x][i]] = rs[x].se;
}
if (!c[h])
dfs(h, a, b);
}
}
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;
}
int z = 0;
map<pair<int, 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())
s[m_p(x + 1, y + 1)] = z++;
if (s.find(m_p(x + 1, y - 1)) == s.end())
s[m_p(x + 1, y - 1)] = z++;
g[u.back()].push_back(v.back());
g[v.back()].push_back(u.back());
gg[s[m_p(x + 1, y + 1)]].push_back(s[m_p(x + 1, y - 1)]);
gg[s[m_p(x + 1, y - 1)]].push_back(s[m_p(x + 1, y + 1)]);
gi[s[m_p(x + 1, y + 1)]].push_back(sz(u) - 1);
gi[s[m_p(x + 1, y - 1)]].push_back(sz(u) - 1);
}
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())
s[m_p(x + 1, y + 1)] = z++;
if (s.find(m_p(x - 1, y + 1)) == s.end())
s[m_p(x - 1, y + 1)] = z++;
g[u.back()].push_back(v.back());
g[v.back()].push_back(u.back());
gg[s[m_p(x + 1, y + 1)]].push_back(s[m_p(x - 1, y + 1)]);
gg[s[m_p(x - 1, y + 1)]].push_back(s[m_p(x + 1, y + 1)]);
gi[s[m_p(x + 1, y + 1)]].push_back(sz(u) - 1);
gi[s[m_p(x - 1, y + 1)]].push_back(sz(u) - 1);
}
}
rs.assign(z, m_p(0, 0));
for (auto it = s.begin(); it != s.end(); ++it)
{
rs[it->se] = it->fi;
}
dfs(0);
for (int i = 0; i < n; ++i)
{
if (!c[i])
return 0;
}
memset(c, false, sizeof c);
a.assign(sz(u), -1);
b.assign(sz(u), -1);
for (int i = 0; i < z; ++i)
{
if (!c[i] && sz(gg[i]) == 1)
{
dfs(i, a, b);
}
}
for (int i = 0; i < z; ++i)
{
if (!c[i])
{
dfs(i, a, b);
}
}
build(u, v, a, b);
return 1;
}
/*
3
2 2
4 2
2 4
3
4 2
2 2
4 4
4
2 2
4 2
2 4
4 4
*/
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)
| ~~^~~~~~~~~~~~~
parks.cpp: In function 'void dfs(int, std::vector<int>&, std::vector<int>&)':
parks.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int i = 0; i < gg[x].size(); ++i)
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
28756 KB |
Output is correct |
2 |
Correct |
12 ms |
28872 KB |
Output is correct |
3 |
Correct |
12 ms |
28372 KB |
Output is correct |
4 |
Correct |
12 ms |
28864 KB |
Output is correct |
5 |
Correct |
14 ms |
28864 KB |
Output is correct |
6 |
Correct |
16 ms |
28372 KB |
Output is correct |
7 |
Correct |
12 ms |
28400 KB |
Output is correct |
8 |
Correct |
12 ms |
28404 KB |
Output is correct |
9 |
Correct |
504 ms |
76736 KB |
Output is correct |
10 |
Correct |
33 ms |
33732 KB |
Output is correct |
11 |
Correct |
184 ms |
54872 KB |
Output is correct |
12 |
Correct |
45 ms |
36256 KB |
Output is correct |
13 |
Correct |
125 ms |
47288 KB |
Output is correct |
14 |
Correct |
14 ms |
28836 KB |
Output is correct |
15 |
Correct |
17 ms |
29264 KB |
Output is correct |
16 |
Correct |
589 ms |
74912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
28756 KB |
Output is correct |
2 |
Correct |
12 ms |
28872 KB |
Output is correct |
3 |
Correct |
12 ms |
28372 KB |
Output is correct |
4 |
Correct |
12 ms |
28864 KB |
Output is correct |
5 |
Correct |
14 ms |
28864 KB |
Output is correct |
6 |
Correct |
16 ms |
28372 KB |
Output is correct |
7 |
Correct |
12 ms |
28400 KB |
Output is correct |
8 |
Correct |
12 ms |
28404 KB |
Output is correct |
9 |
Correct |
504 ms |
76736 KB |
Output is correct |
10 |
Correct |
33 ms |
33732 KB |
Output is correct |
11 |
Correct |
184 ms |
54872 KB |
Output is correct |
12 |
Correct |
45 ms |
36256 KB |
Output is correct |
13 |
Correct |
125 ms |
47288 KB |
Output is correct |
14 |
Correct |
14 ms |
28836 KB |
Output is correct |
15 |
Correct |
17 ms |
29264 KB |
Output is correct |
16 |
Correct |
589 ms |
74912 KB |
Output is correct |
17 |
Incorrect |
18 ms |
28824 KB |
Tree @(3, 3) appears more than once: for edges on positions 1 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
28756 KB |
Output is correct |
2 |
Correct |
12 ms |
28872 KB |
Output is correct |
3 |
Correct |
12 ms |
28372 KB |
Output is correct |
4 |
Correct |
12 ms |
28864 KB |
Output is correct |
5 |
Correct |
14 ms |
28864 KB |
Output is correct |
6 |
Correct |
16 ms |
28372 KB |
Output is correct |
7 |
Correct |
12 ms |
28400 KB |
Output is correct |
8 |
Correct |
12 ms |
28404 KB |
Output is correct |
9 |
Correct |
504 ms |
76736 KB |
Output is correct |
10 |
Correct |
33 ms |
33732 KB |
Output is correct |
11 |
Correct |
184 ms |
54872 KB |
Output is correct |
12 |
Correct |
45 ms |
36256 KB |
Output is correct |
13 |
Correct |
125 ms |
47288 KB |
Output is correct |
14 |
Correct |
14 ms |
28836 KB |
Output is correct |
15 |
Correct |
17 ms |
29264 KB |
Output is correct |
16 |
Correct |
589 ms |
74912 KB |
Output is correct |
17 |
Incorrect |
18 ms |
28824 KB |
Tree @(3, 3) appears more than once: for edges on positions 1 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
28756 KB |
Output is correct |
2 |
Correct |
12 ms |
28872 KB |
Output is correct |
3 |
Correct |
12 ms |
28372 KB |
Output is correct |
4 |
Correct |
12 ms |
28864 KB |
Output is correct |
5 |
Correct |
14 ms |
28864 KB |
Output is correct |
6 |
Correct |
16 ms |
28372 KB |
Output is correct |
7 |
Correct |
12 ms |
28400 KB |
Output is correct |
8 |
Correct |
12 ms |
28404 KB |
Output is correct |
9 |
Correct |
504 ms |
76736 KB |
Output is correct |
10 |
Correct |
33 ms |
33732 KB |
Output is correct |
11 |
Correct |
184 ms |
54872 KB |
Output is correct |
12 |
Correct |
45 ms |
36256 KB |
Output is correct |
13 |
Correct |
125 ms |
47288 KB |
Output is correct |
14 |
Correct |
14 ms |
28836 KB |
Output is correct |
15 |
Correct |
17 ms |
29264 KB |
Output is correct |
16 |
Correct |
589 ms |
74912 KB |
Output is correct |
17 |
Correct |
16 ms |
28796 KB |
Output is correct |
18 |
Correct |
16 ms |
28816 KB |
Output is correct |
19 |
Correct |
14 ms |
28480 KB |
Output is correct |
20 |
Correct |
1125 ms |
106264 KB |
Output is correct |
21 |
Correct |
1211 ms |
99212 KB |
Output is correct |
22 |
Correct |
1068 ms |
99216 KB |
Output is correct |
23 |
Correct |
930 ms |
109760 KB |
Output is correct |
24 |
Correct |
276 ms |
46968 KB |
Output is correct |
25 |
Correct |
997 ms |
108120 KB |
Output is correct |
26 |
Correct |
1010 ms |
108184 KB |
Output is correct |
27 |
Correct |
1323 ms |
117260 KB |
Output is correct |
28 |
Correct |
1284 ms |
117612 KB |
Output is correct |
29 |
Correct |
1401 ms |
117608 KB |
Output is correct |
30 |
Correct |
1332 ms |
117540 KB |
Output is correct |
31 |
Correct |
19 ms |
28756 KB |
Output is correct |
32 |
Correct |
63 ms |
34224 KB |
Output is correct |
33 |
Correct |
97 ms |
38280 KB |
Output is correct |
34 |
Correct |
1152 ms |
108564 KB |
Output is correct |
35 |
Correct |
38 ms |
31428 KB |
Output is correct |
36 |
Correct |
229 ms |
43292 KB |
Output is correct |
37 |
Correct |
445 ms |
58296 KB |
Output is correct |
38 |
Correct |
395 ms |
56504 KB |
Output is correct |
39 |
Correct |
543 ms |
66760 KB |
Output is correct |
40 |
Correct |
747 ms |
77416 KB |
Output is correct |
41 |
Correct |
1080 ms |
87600 KB |
Output is correct |
42 |
Correct |
1250 ms |
97944 KB |
Output is correct |
43 |
Correct |
17 ms |
28884 KB |
Output is correct |
44 |
Correct |
13 ms |
28832 KB |
Output is correct |
45 |
Correct |
13 ms |
28804 KB |
Output is correct |
46 |
Correct |
13 ms |
28484 KB |
Output is correct |
47 |
Correct |
14 ms |
28488 KB |
Output is correct |
48 |
Correct |
15 ms |
28756 KB |
Output is correct |
49 |
Correct |
15 ms |
28848 KB |
Output is correct |
50 |
Correct |
14 ms |
28756 KB |
Output is correct |
51 |
Correct |
13 ms |
28868 KB |
Output is correct |
52 |
Correct |
14 ms |
28484 KB |
Output is correct |
53 |
Correct |
13 ms |
28864 KB |
Output is correct |
54 |
Correct |
21 ms |
29132 KB |
Output is correct |
55 |
Correct |
20 ms |
29432 KB |
Output is correct |
56 |
Correct |
537 ms |
67848 KB |
Output is correct |
57 |
Correct |
815 ms |
85704 KB |
Output is correct |
58 |
Correct |
823 ms |
85404 KB |
Output is correct |
59 |
Correct |
13 ms |
28448 KB |
Output is correct |
60 |
Correct |
12 ms |
28756 KB |
Output is correct |
61 |
Correct |
13 ms |
28484 KB |
Output is correct |
62 |
Correct |
1144 ms |
124396 KB |
Output is correct |
63 |
Correct |
1211 ms |
124684 KB |
Output is correct |
64 |
Correct |
1179 ms |
125140 KB |
Output is correct |
65 |
Correct |
23 ms |
29644 KB |
Output is correct |
66 |
Correct |
33 ms |
30920 KB |
Output is correct |
67 |
Correct |
493 ms |
65692 KB |
Output is correct |
68 |
Correct |
839 ms |
85644 KB |
Output is correct |
69 |
Correct |
1187 ms |
103244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
28756 KB |
Output is correct |
2 |
Correct |
12 ms |
28872 KB |
Output is correct |
3 |
Correct |
12 ms |
28372 KB |
Output is correct |
4 |
Correct |
12 ms |
28864 KB |
Output is correct |
5 |
Correct |
14 ms |
28864 KB |
Output is correct |
6 |
Correct |
16 ms |
28372 KB |
Output is correct |
7 |
Correct |
12 ms |
28400 KB |
Output is correct |
8 |
Correct |
12 ms |
28404 KB |
Output is correct |
9 |
Correct |
504 ms |
76736 KB |
Output is correct |
10 |
Correct |
33 ms |
33732 KB |
Output is correct |
11 |
Correct |
184 ms |
54872 KB |
Output is correct |
12 |
Correct |
45 ms |
36256 KB |
Output is correct |
13 |
Correct |
125 ms |
47288 KB |
Output is correct |
14 |
Correct |
14 ms |
28836 KB |
Output is correct |
15 |
Correct |
17 ms |
29264 KB |
Output is correct |
16 |
Correct |
589 ms |
74912 KB |
Output is correct |
17 |
Correct |
1153 ms |
126700 KB |
Output is correct |
18 |
Correct |
1115 ms |
123892 KB |
Output is correct |
19 |
Correct |
1045 ms |
107940 KB |
Output is correct |
20 |
Correct |
1368 ms |
105800 KB |
Output is correct |
21 |
Correct |
1084 ms |
105476 KB |
Output is correct |
22 |
Correct |
16 ms |
28756 KB |
Output is correct |
23 |
Correct |
135 ms |
40404 KB |
Output is correct |
24 |
Correct |
72 ms |
34856 KB |
Output is correct |
25 |
Correct |
303 ms |
50496 KB |
Output is correct |
26 |
Correct |
586 ms |
66624 KB |
Output is correct |
27 |
Correct |
549 ms |
67800 KB |
Output is correct |
28 |
Correct |
728 ms |
75624 KB |
Output is correct |
29 |
Correct |
935 ms |
87760 KB |
Output is correct |
30 |
Correct |
1141 ms |
96804 KB |
Output is correct |
31 |
Correct |
1526 ms |
106484 KB |
Output is correct |
32 |
Correct |
1527 ms |
115844 KB |
Output is correct |
33 |
Correct |
1293 ms |
127132 KB |
Output is correct |
34 |
Correct |
33 ms |
30164 KB |
Output is correct |
35 |
Correct |
38 ms |
31444 KB |
Output is correct |
36 |
Correct |
505 ms |
68304 KB |
Output is correct |
37 |
Correct |
920 ms |
88716 KB |
Output is correct |
38 |
Correct |
1342 ms |
109124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
28756 KB |
Output is correct |
2 |
Correct |
12 ms |
28872 KB |
Output is correct |
3 |
Correct |
12 ms |
28372 KB |
Output is correct |
4 |
Correct |
12 ms |
28864 KB |
Output is correct |
5 |
Correct |
14 ms |
28864 KB |
Output is correct |
6 |
Correct |
16 ms |
28372 KB |
Output is correct |
7 |
Correct |
12 ms |
28400 KB |
Output is correct |
8 |
Correct |
12 ms |
28404 KB |
Output is correct |
9 |
Correct |
504 ms |
76736 KB |
Output is correct |
10 |
Correct |
33 ms |
33732 KB |
Output is correct |
11 |
Correct |
184 ms |
54872 KB |
Output is correct |
12 |
Correct |
45 ms |
36256 KB |
Output is correct |
13 |
Correct |
125 ms |
47288 KB |
Output is correct |
14 |
Correct |
14 ms |
28836 KB |
Output is correct |
15 |
Correct |
17 ms |
29264 KB |
Output is correct |
16 |
Correct |
589 ms |
74912 KB |
Output is correct |
17 |
Incorrect |
18 ms |
28824 KB |
Tree @(3, 3) appears more than once: for edges on positions 1 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |