№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
How to solve (1292A — NEKO's Maze Game) using DSU
In this problem. How can I solve it using dsu ?
I see the problem has dsu
-tag, but the editorial but doesnt show dsu approach there :(
#include <iostream>
#include <vector>
using namespace std;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vmb;
typedef vector<vi> vmi;
int main()
{
int n, q;
cin >> n >> q;
vmb f(3, vb(n + 2, false));
int delta = 0;
while (q--)
{
int r, c;
cin >> r >> c;
f[r][c].flip();
if (r == 1)
delta += (f[1][c] ? +1 : -1) * (f[2][c - 1] || f[2][c] || f[2][c + 1]);
else
{
delta += (f[2][c] ? +1 : -1) * (f[1][c] && !f[2][c - 1] && !f[2][c + 1]);
delta += (f[2][c] ? +1 : -1) * (f[1][c - 1] && !f[2][c - 1] && !f[2][max(c - 2, 0)]);
delta += (f[2][c] ? +1 : -1) * (f[1][c + 1] && !f[2][c + 1] && !f[2][min(c + 2, n + 1)]);
}
cout << (delta == 0 ? "Yes\n" : "No\n");
}
return 0;
}
Название |
---|