#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
typedef long double ld;
const ld eps = 1e-8;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const ll inf = 1e18;
const ll mod = 1e9 + 7;
#include "parks.h"
vector<vector<int>> g;
vector<int> u, v, a, b;
vector<int> used;
void dfs(int ver) {
used[ver] = 1;
for (auto nod : g[ver]) {
if (!used[nod]) {
u.push_back(ver);
v.push_back(nod);
dfs(nod);
}
}
}
int construct_roads(vector<int> x, vector<int> y) {
bool fir = 1, sec = 1, thi = 1;
int n = x.size();
for (int i = 0; i < n; i++) {
if (x[i] != 2)
fir = 0;
}
map<pair<int, int>, int> mp;
for (int i = 0; i < n; i++) {
mp[{x[i], y[i]}] = i;
}
g.resize(n);
for (int i = 0; i < n; i++) {
if (mp.find({x[i] - 2, y[i]}) != mp.end()) {
g[i].push_back(mp[{x[i] - 2, y[i]}]);
}
if (mp.find({x[i] + 2, y[i]}) != mp.end()) {
g[i].push_back(mp[{x[i] + 2, y[i]}]);
}
if (mp.find({x[i], y[i] - 2}) != mp.end()) {
g[i].push_back(mp[{x[i], y[i] - 2}]);
}
if (mp.find({x[i], y[i] + 2}) != mp.end()) {
g[i].push_back(mp[{x[i], y[i] + 2}]);
}
}
used.resize(n);
dfs(0);
bool ch = 1;
for (int i = 0; i < n; i++) {
if (!used[i])
ch = 0;
}
if (!ch)
return 0;
map<pair<int, int>, int> bench;
map<pair<int, int>, set<int>> want;
set<vector<int>> ben;
for (int i = 0; i < v.size(); i++) {
if (x[v[i]] == x[u[i]]) {
want[{x[v[i]] + 1, (y[v[i]] + y[u[i]]) / 2}].insert(i);
want[{x[v[i]] - 1, (y[v[i]] + y[u[i]]) / 2}].insert(i);
bench[{x[v[i]] + 1, (y[v[i]] + y[u[i]]) / 2}]++;
bench[{x[v[i]] - 1, (y[v[i]] + y[u[i]]) / 2}]++;
} else {
want[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] + 1}].insert(i);
want[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] - 1}].insert(i);
bench[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] + 1}]++;
bench[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] - 1}]++;
}
}
for (auto [pa, cnt] : bench) {
ben.insert({cnt, pa.fi, pa.se});
}
a.resize(n - 1);
b.resize(n - 1);
while(!ben.empty()) {
auto cur = *ben.begin();
int i = *want[{cur[1], cur[2]}].begin();
a[i] = cur[1];
b[i] = cur[2];
if (x[v[i]] == x[u[i]]) {
want[{x[v[i]] + 1, (y[v[i]] + y[u[i]]) / 2}].erase(i);
want[{x[v[i]] - 1, (y[v[i]] + y[u[i]]) / 2}].erase(i);
ben.erase({bench[{x[v[i]] + 1, (y[v[i]] + y[u[i]]) / 2}], x[v[i]] + 1,(y[v[i]] + y[u[i]]) / 2});
ben.erase({bench[{x[v[i]] - 1, (y[v[i]] + y[u[i]]) / 2}], x[v[i]] - 1, (y[v[i]] + y[u[i]]) / 2});
bench[{x[v[i]] + 1, (y[v[i]] + y[u[i]]) / 2}]--;
bench[{x[v[i]] - 1, (y[v[i]] + y[u[i]]) / 2}]--;
if (bench[{x[v[i]] + 1, (y[v[i]] + y[u[i]]) / 2}] > 0) {
ben.insert({bench[{x[v[i]] + 1, (y[v[i]] + y[u[i]]) / 2}], x[v[i]] + 1,(y[v[i]] + y[u[i]]) / 2});
}
if (bench[{x[v[i]] - 1, (y[v[i]] + y[u[i]]) / 2}] > 0) {
ben.insert({bench[{x[v[i]] - 1, (y[v[i]] + y[u[i]]) / 2}], x[v[i]] - 1, (y[v[i]] + y[u[i]]) / 2});
}
} else {
want[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] + 1}].erase(i);
want[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] - 1}].erase(i);
ben.erase({bench[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] + 1}],(x[v[i]] + x[u[i]]) / 2, y[v[i]] + 1 });
ben.erase({bench[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] - 1}], (x[v[i]] + x[u[i]]) / 2, y[v[i]] - 1});
bench[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] + 1}]--;
bench[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] - 1}]--;
if ( bench[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] + 1}] > 0) {
ben.insert({bench[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] + 1}],(x[v[i]] + x[u[i]]) / 2, y[v[i]] + 1 });
}
if (bench[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] - 1}] > 0) {
ben.insert({bench[{(x[v[i]] + x[u[i]]) / 2, y[v[i]] - 1}], (x[v[i]] + x[u[i]]) / 2, y[v[i]] - 1});
}
}
}
build(u, v, a, b);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:71:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
parks.cpp:34:10: warning: variable 'fir' set but not used [-Wunused-but-set-variable]
34 | bool fir = 1, sec = 1, thi = 1;
| ^~~
parks.cpp:34:19: warning: unused variable 'sec' [-Wunused-variable]
34 | bool fir = 1, sec = 1, thi = 1;
| ^~~
parks.cpp:34:28: warning: unused variable 'thi' [-Wunused-variable]
34 | bool fir = 1, sec = 1, thi = 1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
440 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
336 ms |
84728 KB |
Output is correct |
10 |
Correct |
23 ms |
8772 KB |
Output is correct |
11 |
Correct |
162 ms |
46048 KB |
Output is correct |
12 |
Correct |
38 ms |
12884 KB |
Output is correct |
13 |
Correct |
28 ms |
9052 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
345 ms |
82136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
440 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
336 ms |
84728 KB |
Output is correct |
10 |
Correct |
23 ms |
8772 KB |
Output is correct |
11 |
Correct |
162 ms |
46048 KB |
Output is correct |
12 |
Correct |
38 ms |
12884 KB |
Output is correct |
13 |
Correct |
28 ms |
9052 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
345 ms |
82136 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
826 ms |
118056 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
1012 KB |
Output is correct |
28 |
Correct |
288 ms |
48068 KB |
Output is correct |
29 |
Correct |
475 ms |
70260 KB |
Output is correct |
30 |
Correct |
631 ms |
95164 KB |
Output is correct |
31 |
Correct |
837 ms |
117012 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
860 KB |
Output is correct |
45 |
Correct |
361 ms |
67192 KB |
Output is correct |
46 |
Correct |
535 ms |
97508 KB |
Output is correct |
47 |
Correct |
563 ms |
97052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
440 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
336 ms |
84728 KB |
Output is correct |
10 |
Correct |
23 ms |
8772 KB |
Output is correct |
11 |
Correct |
162 ms |
46048 KB |
Output is correct |
12 |
Correct |
38 ms |
12884 KB |
Output is correct |
13 |
Correct |
28 ms |
9052 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
345 ms |
82136 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
826 ms |
118056 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
1012 KB |
Output is correct |
28 |
Correct |
288 ms |
48068 KB |
Output is correct |
29 |
Correct |
475 ms |
70260 KB |
Output is correct |
30 |
Correct |
631 ms |
95164 KB |
Output is correct |
31 |
Correct |
837 ms |
117012 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
860 KB |
Output is correct |
45 |
Correct |
361 ms |
67192 KB |
Output is correct |
46 |
Correct |
535 ms |
97508 KB |
Output is correct |
47 |
Correct |
563 ms |
97052 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
436 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
344 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
344 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
851 ms |
116056 KB |
Output is correct |
56 |
Incorrect |
0 ms |
348 KB |
Tree @(3, 183571) appears more than once: for edges on positions 1 and 2 |
57 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
440 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
336 ms |
84728 KB |
Output is correct |
10 |
Correct |
23 ms |
8772 KB |
Output is correct |
11 |
Correct |
162 ms |
46048 KB |
Output is correct |
12 |
Correct |
38 ms |
12884 KB |
Output is correct |
13 |
Correct |
28 ms |
9052 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
345 ms |
82136 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
717 ms |
120200 KB |
Output is correct |
21 |
Correct |
694 ms |
117248 KB |
Output is correct |
22 |
Correct |
746 ms |
115980 KB |
Output is correct |
23 |
Correct |
606 ms |
140564 KB |
Output is correct |
24 |
Correct |
195 ms |
22352 KB |
Output is correct |
25 |
Correct |
277 ms |
28740 KB |
Output is correct |
26 |
Correct |
272 ms |
28752 KB |
Output is correct |
27 |
Correct |
696 ms |
156948 KB |
Output is correct |
28 |
Correct |
688 ms |
157040 KB |
Output is correct |
29 |
Correct |
838 ms |
156956 KB |
Output is correct |
30 |
Correct |
846 ms |
157036 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
39 ms |
9276 KB |
Tree @(185705, 20641) appears more than once: for edges on positions 81 and 82 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
440 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
336 ms |
84728 KB |
Output is correct |
10 |
Correct |
23 ms |
8772 KB |
Output is correct |
11 |
Correct |
162 ms |
46048 KB |
Output is correct |
12 |
Correct |
38 ms |
12884 KB |
Output is correct |
13 |
Correct |
28 ms |
9052 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
345 ms |
82136 KB |
Output is correct |
17 |
Correct |
748 ms |
170000 KB |
Output is correct |
18 |
Correct |
773 ms |
168832 KB |
Output is correct |
19 |
Correct |
689 ms |
120180 KB |
Output is correct |
20 |
Incorrect |
763 ms |
128424 KB |
Tree @(269, 877) appears more than once: for edges on positions 168228 and 168229 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
440 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
336 ms |
84728 KB |
Output is correct |
10 |
Correct |
23 ms |
8772 KB |
Output is correct |
11 |
Correct |
162 ms |
46048 KB |
Output is correct |
12 |
Correct |
38 ms |
12884 KB |
Output is correct |
13 |
Correct |
28 ms |
9052 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
345 ms |
82136 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
826 ms |
118056 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
1012 KB |
Output is correct |
28 |
Correct |
288 ms |
48068 KB |
Output is correct |
29 |
Correct |
475 ms |
70260 KB |
Output is correct |
30 |
Correct |
631 ms |
95164 KB |
Output is correct |
31 |
Correct |
837 ms |
117012 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
860 KB |
Output is correct |
45 |
Correct |
361 ms |
67192 KB |
Output is correct |
46 |
Correct |
535 ms |
97508 KB |
Output is correct |
47 |
Correct |
563 ms |
97052 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
436 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
344 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
344 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
851 ms |
116056 KB |
Output is correct |
56 |
Incorrect |
0 ms |
348 KB |
Tree @(3, 183571) appears more than once: for edges on positions 1 and 2 |
57 |
Halted |
0 ms |
0 KB |
- |