poj1703 find them,catch them
来源:互联网 发布:js 字符串转义 编辑:程序博客网 时间:2024/05/20 00:52
Find them, Catch them
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 37315 Accepted: 11508
Description
The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which gang a criminal belongs to. The present question is, given two criminals; do they belong to a same clan? You must give your judgment based on incomplete information. (Since the gangsters are always acting secretly.)
Assume N (N <= 10^5) criminals are currently in Tadu City, numbered from 1 to N. And of course, at least one of them belongs to Gang Dragon, and the same for Gang Snake. You will be given M (M <= 10^5) messages in sequence, which are in the following two kinds:
1. D [a] [b]
where [a] and [b] are the numbers of two criminals, and they belong to different gangs.
2. A [a] [b]
where [a] and [b] are the numbers of two criminals. This requires you to decide whether a and b belong to a same gang.
Assume N (N <= 10^5) criminals are currently in Tadu City, numbered from 1 to N. And of course, at least one of them belongs to Gang Dragon, and the same for Gang Snake. You will be given M (M <= 10^5) messages in sequence, which are in the following two kinds:
1. D [a] [b]
where [a] and [b] are the numbers of two criminals, and they belong to different gangs.
2. A [a] [b]
where [a] and [b] are the numbers of two criminals. This requires you to decide whether a and b belong to a same gang.
Input
The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. Each test case begins with a line with two integers N and M, followed by M lines each containing one message as described above.
Output
For each message "A [a] [b]" in each case, your program should give the judgment based on the information got before. The answers might be one of "In the same gang.", "In different gangs." and "Not sure yet."
Sample Input
15 5A 1 2D 1 2A 1 2D 2 4A 1 4
Sample Output
Not sure yet.In different gangs.In the same gang.
#include <iostream>#include<cstdio>using namespace std;const int maxn=100000+5;int n,m;int set[maxn+maxn];int set_find(int d){ if(set[d]<0) return d; return set[d]=set_find(set[d]);}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) set[i]=-1; for(int i=0;i<m;i++) { int a,b; char c[5]; scanf("%s%d%d",c,&a,&b); if(c[0]=='A') { if(set_find(a)!=set_find(b)&&set_find(a)!=set_find(b+n)) printf("%s\n","Not sure yet."); else if(set_find(a)==set_find(b)) printf("%s\n","In the same gang."); else printf("%s\n","In diffirent gang."); } else { if(set_find(a)!=set_find(b+n)) { set[set_find(a)]=set_find(b+n); set[set_find(b)]=set_find(a+n); } } } } return 0;}
0 0
- poj1703 - Find them, Catch them
- POJ1703 Find them, Catch them
- poj1703 Find them, Catch them
- poj1703 Find them, Catch them
- POJ1703 Find them,Catch them
- POJ1703--Find them, Catch them
- poj1703 find them,catch them
- Find them, Catch them poj1703
- POJ1703 Find them, Catch them
- poj1703 Find them, Catch them
- poj1703 Find them, Catch them
- POJ1703-Find them, Catch them
- POJ1703 Find them, Catch them
- poj1703 Find them, Catch them
- poj1703 Find them, Catch them
- poj1703——Find them, Catch them
- poj1703——Find them, Catch them
- Find them, Catch them (poj1703)
- Codeforces Round #325 (Div. 2) C. Gennady the Dentist(水题)
- html禁用缓存
- Spring 连接MySQL 数据库
- DirectShow的配置及从摄像头读取视频并预览
- 解决casperjs脚本输出中文乱码问题
- poj1703 find them,catch them
- xcode APP 打包以及提交apple审核详细流程(新版本更新提交审核)
- usbredir-0.7内容详解(二)
- 26.Struts2文件下载并在下载文件之前进行权限检查
- 网站所有页面都在新窗口打开
- fpga闪烁的led灯
- 经典的面试题:用 4 个线程疯狂的打印 abcd 持续 5 秒钟,但是要按照顺序打印,不能是乱序的。
- 多条件查询
- OCdemo-07 CateGory 类目