1 条题解
-
0
#include <bits/stdc++.h> using namespace std; int n, m; int fa[40005]; int findFa(int x) { if (x == fa[x]) return x; return fa[x] = findFa(fa[x]); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n * n; i++) fa[i] = i; for (int step = 1; step <= m; step++) { int x, y, xx, yy; char c; cin >> x >> y >> c; if (c == 'D') xx = x + 1, yy = y; else if (c == 'R') xx = x, yy = y + 1; int u = (x - 1) * n + y; int v = (xx - 1) * n + yy; int faU = findFa(u); int faV = findFa(v); if (faU == faV) { cout << step; return 0; } else { fa[faU] = faV; } } cout << "draw\n"; return 0; }
- 1
信息
- ID
- 566
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 5
- 标签
- (无)
- 递交数
- 59
- 已通过
- 25
- 上传者