POJ 1733 Parity game——并查集 + 离散化
来源:互联网 发布:ubuntu ntp server 编辑:程序博客网 时间:2024/06/06 03:55
#include <cstdio>#include <algorithm>using namespace std;const int maxn = 1e4 + 10;int T, N, M, par[maxn], val[maxn], a[maxn];struct Date { char str[10]; int x, y;}date[maxn];int Query(int x) { if (x != par[x]) { int temp = par[x]; par[x] = Query(par[x]); val[x] = val[x] ^ val[temp]; } return par[x];}int main() { while (~scanf("%d %d", &N, &M)) { int cnt = 0; for (int i = 1; i <= M; i++) { scanf("%d%d%s", &date[i].x, &date[i].y, date[i].str); date[i].x--; a[++cnt] = date[i].x; a[++cnt] = date[i].y; } sort(a + 1, a + 1 + cnt); cnt = unique(a + 1, a + 1 + cnt) - a; for (int i = 1; i <= cnt; i++) par[i] = i, val[i] = 0; int ans = 0; for (int i = 1; i <= M; i++) { int x = lower_bound(a + 1, a + 1 + cnt, date[i].x) - a; int y = lower_bound(a + 1, a + 1 + cnt, date[i].y) - a; int a = Query(x), b = Query(y); if (a == b) { if ((val[x] ^ val[y]) % 2 == 0 && date[i].str[0] == 'o') break; if ((val[x] ^ val[y]) % 2 == 1 && date[i].str[0] == 'e') break; ans++; } else { if (date[i].str[0] == 'o') { par[a] = b; val[a] = val[x] ^ val[y] ^ 1; } else { par[a] = b; val[a] = val[x] ^ val[y]; } ans++; } } printf("%d\n", ans); }}
阅读全文
1 0
- poj 1733 - Parity game(离散化+并查集)
- poj 1733 Parity game 并查集 离散化
- poj 1733 Parity game 【种类并查集+离散化】
- Poj 1733 Parity Game(离散化+并查集)
- POJ 1733 Parity game——并查集 + 离散化
- POJ 1733 parity game (hash离散+并查集)
- poj 1733 Parity game 【离散+并查集】
- POJ Parity game 离散化+并查集
- POJ 1733 Parity game(路径压缩并查集+离散化)
- poj 1733 Parity game(带权并查集+离散化)
- POJ 1733 Parity game(离散化+带权并查集)
- POJ 1733Parity game 离散化+带权并查集
- POJ - 1733 Parity game 带权并查集+离散化
- POJ 1733 Parity game(离散化 + 带权并查集)
- POJ 1733 Parity game(离散化+带权并查集)
- poj 1733 Parity game (带权并查集)(离散化)
- poj 1733 Parity game 离散化+带权并查集(区间)
- poj 1733 Parity game(离散化+带权并查集+二分查找)
- 【UVA1629】Cake slicing
- 自定义带进度条WebView类似微信加载过程
- 利用百度地图API和群蚁算法,对TSP问题进行模拟与求解
- 在realm中动态查询用户的权限&角色
- electron仿制UnrealEngine4 蓝图功能模块
- POJ 1733 Parity game——并查集 + 离散化
- 从零开始接入腾讯云智能推荐
- jetty换启动端口
- mysql:union与union all的区别
- Name node is in safe mode 解除安全模式
- 拆带13个字节帧头的264文件
- Spring bean factory
- POJ 3292 Semi-prime H-numbers
- Android6.0权限申请