№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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;
}
Название |
---|