#include "parks.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef set<int> si;
struct pii{int a, b;};
bool operator <(pii a, pii b) {return a.a < b.a || a.a == b.a && a.b < b.b;}
const int MD = 2e5 + 10;
bool conn(int n, vi& u, vi& v) {
vvi adj(n);
forR(i, n) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
vb vis(n);
vi dfs = {0};
while(!dfs.empty()) {
int cur = dfs.back(); dfs.pop_back();
if(!vis[cur]) {
vis[cur] = true;
for(int i : adj[cur]) if(!vis[i]) {
dfs.push_back(i);
}
}
}
forR(i, n) if(!vis[i]) return false;
return true;
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
int n = x.size();
map<pii, int> ci;
forR(i, n) ci[{x[i], y[i]}] = i;
vi u, v, a, b;
for(auto [co, id] : ci) {
if(ci.count({co.a, co.b + 2})) {
u.push_back(id);
v.push_back(ci[{co.a, co.b+2}]);
a.push_back(co.a - 1);
b.push_back(co.b + 1);
}
}
for(int y = 2; y < MD; y += 2) {
if(ci.count({4, y}) && ci.count({2, y})) {
u.push_back(ci[{2, y}]);
v.push_back(ci[{4, y}]);
a.push_back(3);
b.push_back(y + 1);
}
}
build(u, v, a, b);
return 1;
}
Compilation message
parks.cpp: In function 'bool operator<(pii, pii)':
parks.cpp:12:63: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
12 | bool operator <(pii a, pii b) {return a.a < b.a || a.a == b.a && a.b < b.b;}
| ~~~~~~~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |