#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define ll long long
#define db double
#define pb push_back
#define pf push_front
#define newl "\n"
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second
#define MOD 1000000007
using namespace std;
#pragma GCC diagnostic ignored "-Wunused-result"
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
cout << fixed << setprecision(15);
if (name.size()) {
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
ll c = 0;
map <pair <ll, ll>, bool> vis, exist;
unordered_map <ll, bool> occ;
void C(ll x, ll y)
{
if (exist[{x, y}] && !vis[{x, y}])
{
vis[{x, y}] = true;
c++;
if (!vis[{x + 1, y}])
{
C(x + 1, y);
}
if (!vis[{x - 1, y}])
{
C(x - 1, y);
}
if (!vis[{x, y + 1}])
{
C(x, y + 1);
}
if (!vis[{x, y - 1}])
{
C(x, y - 1);
}
if (!vis[{x + 1, y + 1}])
{
C(x + 1, y + 1);
}
if (!vis[{x + 1, y - 1}])
{
C(x + 1, y - 1);
}
if (!vis[{x - 1, y + 1}])
{
C(x - 1, y + 1);
}
if (!vis[{x - 1, y - 1}])
{
C(x - 1, y - 1);
}
}
}
bool cyc = 0;
void dfs(ll px, ll py, ll x, ll y)
{
if (exist[{x, y}])
{
vis[{x, y}] = true;
if (!vis[{x + 1, y}])
{
dfs(x, y, x + 1, y);
}
else if (px != x + 1 && py != y)
{
cyc = true;
}
if (!vis[{x - 1, y}])
{
dfs(x, y, x - 1, y);
}
else if (px != x - 1 && py != y)
{
cyc = true;
}
if (!vis[{x, y + 1}])
{
dfs(x, y, x, y + 1);
}
else if (px != x && py != y + 1)
{
cyc = true;
}
if (!vis[{x, y - 1}])
{
dfs(x, y, x, y - 1);
}
else if (px != x && py != y - 1)
{
cyc = true;
}
}
}
int main()
{
//fast
//setIO("");
//freopen("filename.in", "r", stdin);
//freopen("filename.out", "w", stdout);
ll n, t; cin >> n >> t;
vector <pair <ll, ll>> a(n);
for (ll i = 0; i < n; i++)
{
cin >> a[i].f >> a[i].s;
exist[a[i]] = true;
}
C(a[0].f, a[0].s);
//cout << newl << c << newl << newl << newl;
if (c != n)
{
cout << "NO";
return 0;
}
vector <ll> ans;
for (ll i = 0; i < n; i++)
{
if (vis.size()) vis.clear();
cyc = 0;
dfs(a[i].f, a[i].s, a[i].f, a[i].s);
if (cyc) occ[i] = true;
}
if (ans.size() > 1)
{
cout << "NO";
return 0;
}
cout << "YES" << newl;
for (ll i = 0; i < n; i++)
{
if (!occ[i]) cout << i + 1 << newl;
}
for (ll i = 0; i < n; i++)
{
if (occ[i]) cout << i + 1 << newl;
}
//cout << 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
212 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
212 KB |
ans=NO N=4 |
4 |
Correct |
1 ms |
212 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
6 |
Correct |
1 ms |
212 KB |
ans=YES N=5 |
7 |
Correct |
1 ms |
212 KB |
ans=NO N=9 |
8 |
Correct |
0 ms |
212 KB |
ans=NO N=10 |
9 |
Incorrect |
0 ms |
212 KB |
Full cells must be connected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
212 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
212 KB |
ans=NO N=4 |
4 |
Correct |
1 ms |
212 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
6 |
Correct |
1 ms |
212 KB |
ans=YES N=5 |
7 |
Correct |
1 ms |
212 KB |
ans=NO N=9 |
8 |
Correct |
0 ms |
212 KB |
ans=NO N=10 |
9 |
Incorrect |
0 ms |
212 KB |
Full cells must be connected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
212 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
212 KB |
ans=NO N=4 |
4 |
Correct |
1 ms |
212 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
6 |
Correct |
1 ms |
212 KB |
ans=YES N=5 |
7 |
Correct |
1 ms |
212 KB |
ans=NO N=9 |
8 |
Correct |
0 ms |
212 KB |
ans=NO N=10 |
9 |
Incorrect |
0 ms |
212 KB |
Full cells must be connected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
ans=NO N=1934 |
2 |
Correct |
2 ms |
468 KB |
ans=NO N=1965 |
3 |
Incorrect |
1856 ms |
920 KB |
Full cells must be connected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
212 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
212 KB |
ans=NO N=4 |
4 |
Correct |
1 ms |
212 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
6 |
Correct |
1 ms |
212 KB |
ans=YES N=5 |
7 |
Correct |
1 ms |
212 KB |
ans=NO N=9 |
8 |
Correct |
0 ms |
212 KB |
ans=NO N=10 |
9 |
Incorrect |
0 ms |
212 KB |
Full cells must be connected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
187 ms |
18892 KB |
ans=NO N=66151 |
2 |
Correct |
47 ms |
5272 KB |
ans=NO N=64333 |
3 |
Execution timed out |
3569 ms |
16716 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
ans=NO N=1934 |
2 |
Correct |
2 ms |
468 KB |
ans=NO N=1965 |
3 |
Incorrect |
1856 ms |
920 KB |
Full cells must be connected |
4 |
Halted |
0 ms |
0 KB |
- |