#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);
}
}
vector<pair<int, int> > rs;
vector<int> gg[N * 2], gi[N * 2];
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(sz(s), 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])
{
dfs(i, a, b);
}
}
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)
| ~~^~~~~~~~~~~~~
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)
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23892 KB |
Output is correct |
2 |
Correct |
13 ms |
23924 KB |
Output is correct |
3 |
Correct |
12 ms |
23792 KB |
Output is correct |
4 |
Correct |
12 ms |
23980 KB |
Output is correct |
5 |
Correct |
12 ms |
23916 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
12 ms |
23720 KB |
Output is correct |
8 |
Correct |
13 ms |
23748 KB |
Output is correct |
9 |
Correct |
452 ms |
72604 KB |
Output is correct |
10 |
Correct |
31 ms |
28928 KB |
Output is correct |
11 |
Correct |
167 ms |
50304 KB |
Output is correct |
12 |
Correct |
42 ms |
31388 KB |
Output is correct |
13 |
Correct |
113 ms |
42800 KB |
Output is correct |
14 |
Correct |
14 ms |
24120 KB |
Output is correct |
15 |
Correct |
16 ms |
24592 KB |
Output is correct |
16 |
Correct |
484 ms |
70812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23892 KB |
Output is correct |
2 |
Correct |
13 ms |
23924 KB |
Output is correct |
3 |
Correct |
12 ms |
23792 KB |
Output is correct |
4 |
Correct |
12 ms |
23980 KB |
Output is correct |
5 |
Correct |
12 ms |
23916 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
12 ms |
23720 KB |
Output is correct |
8 |
Correct |
13 ms |
23748 KB |
Output is correct |
9 |
Correct |
452 ms |
72604 KB |
Output is correct |
10 |
Correct |
31 ms |
28928 KB |
Output is correct |
11 |
Correct |
167 ms |
50304 KB |
Output is correct |
12 |
Correct |
42 ms |
31388 KB |
Output is correct |
13 |
Correct |
113 ms |
42800 KB |
Output is correct |
14 |
Correct |
14 ms |
24120 KB |
Output is correct |
15 |
Correct |
16 ms |
24592 KB |
Output is correct |
16 |
Correct |
484 ms |
70812 KB |
Output is correct |
17 |
Incorrect |
13 ms |
23904 KB |
Tree @(3, 3) appears more than once: for edges on positions 1 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23892 KB |
Output is correct |
2 |
Correct |
13 ms |
23924 KB |
Output is correct |
3 |
Correct |
12 ms |
23792 KB |
Output is correct |
4 |
Correct |
12 ms |
23980 KB |
Output is correct |
5 |
Correct |
12 ms |
23916 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
12 ms |
23720 KB |
Output is correct |
8 |
Correct |
13 ms |
23748 KB |
Output is correct |
9 |
Correct |
452 ms |
72604 KB |
Output is correct |
10 |
Correct |
31 ms |
28928 KB |
Output is correct |
11 |
Correct |
167 ms |
50304 KB |
Output is correct |
12 |
Correct |
42 ms |
31388 KB |
Output is correct |
13 |
Correct |
113 ms |
42800 KB |
Output is correct |
14 |
Correct |
14 ms |
24120 KB |
Output is correct |
15 |
Correct |
16 ms |
24592 KB |
Output is correct |
16 |
Correct |
484 ms |
70812 KB |
Output is correct |
17 |
Incorrect |
13 ms |
23904 KB |
Tree @(3, 3) appears more than once: for edges on positions 1 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23892 KB |
Output is correct |
2 |
Correct |
13 ms |
23924 KB |
Output is correct |
3 |
Correct |
12 ms |
23792 KB |
Output is correct |
4 |
Correct |
12 ms |
23980 KB |
Output is correct |
5 |
Correct |
12 ms |
23916 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
12 ms |
23720 KB |
Output is correct |
8 |
Correct |
13 ms |
23748 KB |
Output is correct |
9 |
Correct |
452 ms |
72604 KB |
Output is correct |
10 |
Correct |
31 ms |
28928 KB |
Output is correct |
11 |
Correct |
167 ms |
50304 KB |
Output is correct |
12 |
Correct |
42 ms |
31388 KB |
Output is correct |
13 |
Correct |
113 ms |
42800 KB |
Output is correct |
14 |
Correct |
14 ms |
24120 KB |
Output is correct |
15 |
Correct |
16 ms |
24592 KB |
Output is correct |
16 |
Correct |
484 ms |
70812 KB |
Output is correct |
17 |
Correct |
12 ms |
23896 KB |
Output is correct |
18 |
Correct |
11 ms |
23900 KB |
Output is correct |
19 |
Correct |
12 ms |
23764 KB |
Output is correct |
20 |
Incorrect |
956 ms |
101572 KB |
Tree @(192371, 7633) appears more than once: for edges on positions 0 and 1 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23892 KB |
Output is correct |
2 |
Correct |
13 ms |
23924 KB |
Output is correct |
3 |
Correct |
12 ms |
23792 KB |
Output is correct |
4 |
Correct |
12 ms |
23980 KB |
Output is correct |
5 |
Correct |
12 ms |
23916 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
12 ms |
23720 KB |
Output is correct |
8 |
Correct |
13 ms |
23748 KB |
Output is correct |
9 |
Correct |
452 ms |
72604 KB |
Output is correct |
10 |
Correct |
31 ms |
28928 KB |
Output is correct |
11 |
Correct |
167 ms |
50304 KB |
Output is correct |
12 |
Correct |
42 ms |
31388 KB |
Output is correct |
13 |
Correct |
113 ms |
42800 KB |
Output is correct |
14 |
Correct |
14 ms |
24120 KB |
Output is correct |
15 |
Correct |
16 ms |
24592 KB |
Output is correct |
16 |
Correct |
484 ms |
70812 KB |
Output is correct |
17 |
Runtime error |
1173 ms |
231608 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23892 KB |
Output is correct |
2 |
Correct |
13 ms |
23924 KB |
Output is correct |
3 |
Correct |
12 ms |
23792 KB |
Output is correct |
4 |
Correct |
12 ms |
23980 KB |
Output is correct |
5 |
Correct |
12 ms |
23916 KB |
Output is correct |
6 |
Correct |
12 ms |
23792 KB |
Output is correct |
7 |
Correct |
12 ms |
23720 KB |
Output is correct |
8 |
Correct |
13 ms |
23748 KB |
Output is correct |
9 |
Correct |
452 ms |
72604 KB |
Output is correct |
10 |
Correct |
31 ms |
28928 KB |
Output is correct |
11 |
Correct |
167 ms |
50304 KB |
Output is correct |
12 |
Correct |
42 ms |
31388 KB |
Output is correct |
13 |
Correct |
113 ms |
42800 KB |
Output is correct |
14 |
Correct |
14 ms |
24120 KB |
Output is correct |
15 |
Correct |
16 ms |
24592 KB |
Output is correct |
16 |
Correct |
484 ms |
70812 KB |
Output is correct |
17 |
Incorrect |
13 ms |
23904 KB |
Tree @(3, 3) appears more than once: for edges on positions 1 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |