0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:28:47 +00:00
Baoshuo Ren 2021-08-12 11:29:44 +08:00 committed by Baoshuo Ren
parent 55a83b71b5
commit 8530a5145b
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

40
AcWing/1250/1250.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, fa[40005], res;
char d;
int get(int x, int y) {
return x * n + y;
}
int find(int x) {
return fa[x] == x ? fa[x] : fa[x] = find(fa[x]);
}
int main() {
cin >> n >> m;
for (int i = 0; i < n * n; i++) {
fa[i] = i;
}
for (int i = 1; i <= m; i++) {
cin >> x >> y >> d;
int a = get(--x, --y);
int b = d == 'D' ? get(x + 1, y) : get(x, y + 1);
int pa = find(a);
int pb = find(b);
if (pa == pb) {
res = i;
break;
} else {
fa[pa] = pb;
}
}
if (!res) {
cout << "draw" << endl;
} else {
cout << res << endl;
}
return 0;
}