This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
struct Point {
int r, c;
};
auto compPoint = [](Point a, Point b) {
return std::make_pair(a.r, a.c) < std::make_pair(b.r, b.c);
};
std::pair<int, int> dxy[8] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}};
int main() {
int N, T;
std::cin >> N >> T;
std::vector<Point> sks(N);
for (auto &[r, c] : sks) {
std::cin >> r >> c;
}
std::map<Point, int, decltype(compPoint)> skMap(compPoint);
for (int i = 0; i < N; ++i) {
skMap[sks[i]] = i;
}
std::vector<int> dist(N, -1);
dist[0] = 0;
std::queue<int> que;
que.push(0);
while (not que.empty()) {
const auto f = que.front();
que.pop();
const auto &[r, c] = sks[f];
for (const auto &[ar, ac] : dxy) {
const int nr = r + ar, nc = c + ac;
auto itr = skMap.find({nr, nc});
if (itr == skMap.end()) {
continue;
}
const int t = itr->second;
if (dist[t] != -1) {
continue;
}
dist[t] = dist[f] + 1;
que.push(t);
}
}
if (std::any_of(dist.begin(), dist.end(), [&](int x) {
return x == -1;
})) {
std::cout << "NO" << std::endl;
return 0;
}
std::cout << "YES" << std::endl;
std::vector<std::vector<int>> distList(N);
for (int i = 0; i < N; ++i) {
distList[dist[i]].push_back(i);
}
for (const auto &vec : distList) {
for (const auto e : vec) {
std::cout << e + 1 << std::endl;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |