#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define F first
#define S second
vector<vector<int>> g;
vector<bool> vis;
int c = 0;
void search(int i) {
vis[i] = 1; c++;
for(auto x: g[i]) if(!vis[x]) search(x);
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
int n = x.size();
vis.resize(n,0);
g.resize(n);
vector<iii> p;
for(int i = 0; i < n; i++) p.push_back({{x[i],y[i]},i});
sort(p.begin(),p.end());
vector<ii> roads;
for(int i = 0; i < n-1; i++) {
if(p[i].F.F == p[i+1].F.F && p[i+1].F.S-p[i].F.S == 2) {
roads.emplace_back(p[i].S, p[i+1].S);
g[p[i].S].push_back(p[i+1].S);
g[p[i+1].S].push_back(p[i].S);
}
}
for(int i = 0; i < n; i++) swap(p[i].F.F,p[i].F.S);
sort(p.begin(),p.end());
for(int i = 0; i < n; i++) swap(p[i].F.F,p[i].F.S);
for(int i = 0; i < n-1; i++) {
if(p[i].F.S == p[i+1].F.S && p[i+1].F.F-p[i].F.F == 2) {
roads.emplace_back(p[i].S, p[i+1].S);
g[p[i].S].push_back(p[i+1].S);
g[p[i+1].S].push_back(p[i].S);
}
}
int m = roads.size();
search(0);
if(c < n) return 0;
vector<ii> ben(m);
for(int i = 0; i < m; i++) {
if(x[roads[i].F] == x[roads[i].S]) {
if(x[roads[i].F] == 2) ben[i] = {1, (y[roads[i].F]+y[roads[i].S])/2};
else ben[i] = {5, (y[roads[i].F]+y[roads[i].S])/2};
} else ben[i] = {3, y[roads[i].F]+1};
}
vector<int> u(m), v(m), a(m), b(m);
for(int i = 0; i < n; i++) {
u[i] = roads[i].F; v[i] = roads[i].S;
a[i] = ben[i].F; b[i] = ben[i].S;
}
build(u, v, a, b);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |