POJ 1703 Find themCatch them
来源:互联网 发布:印度 撤军 知乎 编辑:程序博客网 时间:2024/04/28 11:21
这类题有一点类似,那就是需要定义状态,且题目越复杂,状态越多,如果状态多,定义状态的时候要与题目给出的关系有一定联系。
//// main.cpp// Richard//// Created by 邵金杰 on 16/7/24.// Copyright © 2016年 邵金杰. All rights reserved.//#include<iostream>#include<cstdio>using namespace std;const int maxn=100000+100;int pa[maxn],re[maxn];int getroot(int a){ if(pa[a]==a) return a; int t=getroot(pa[a]); re[a]=(re[a]+re[pa[a]])%2; pa[a]=t; return pa[a];}void Union(int x,int y,int a,int b){ pa[b]=a; re[b]=(1+re[y]+re[x])%2;}int main(){ int t,m,n,x,y; char cmd[10]; scanf("%d",&t); while(t--) { scanf("%d%d",&m,&n); for(int i=1;i<=m;i++) pa[i]=i,re[i]=0; for(int i=0;i<n;i++){ scanf("%s%d%d",cmd,&x,&y); int a,b; a=getroot(x); b=getroot(y); if(cmd[0]=='D') Union(x,y,a,b); else{ if(a!=b) printf("Not sure yet.\n"); else{ if(re[x]==re[y]) printf("In the same gang.\n"); else printf("In different gangs.\n"); } } } } return 0;}
0 0
- POJ 1703 Find themCatch them
- POJ 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- POJ-1703 Find them, Catch them
- Poj 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- POJ 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- POJ 1703 - Find them, Catch them
- POJ 1703 Find them, Catch them
- POJ 1703(Find them, Catch them)
- POJ 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- POJ 1703: Find them, Catch them
- poj 1703 find them,catch them
- POJ--1703--Find them, Catch them
- python模拟登录qq邮箱
- Jenkins安装配置
- 覆盖索引
- java并发编程之CyclicBarrier
- css书写顺序
- POJ 1703 Find themCatch them
- 今日头条编程题 专辑问题
- 超级表格创始人中学时代揭秘
- 图片做边框
- 最优化学习笔记(六)——牛顿法性质分析
- 最优化学习笔记(六)——牛顿法性质分析
- [javascript权威指南][阅读笔记]脚本化文档
- Android SQLite
- 1个球从 100 的由落下,每次落地后反弹回原高度的一半,再落下,再反弹。第10次落地时,经过多少米,第 10 次反弹多少米