Practice Round APAC test Problem A. Bad Horse 2-sat
来源:互联网 发布:声鉴软件 编辑:程序博客网 时间:2024/05/01 18:36
Problem A. Bad Horse
12 points
21 points
Problem
As the leader of the Evil League of Evil, Bad Horse has a lot of problems to deal with. Most recently, there have been far too many arguments and far too much backstabbing in the League, so much so that Bad Horse has decided to split the league into two departments in order to separate troublesome members. Being the Thoroughbred of Sin, Bad Horse isn't about to spend his valuable time figuring out how to split the League members by himself. That what he's got you -- his loyal henchman -- for.
Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with a positive integer M on a line by itself -- the number of troublesome pairs of League members. The next M lines each contain a pair of names, separated by a single space.
Output
For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is either "Yes" or "No", depending on whether the League members mentioned in the input can be split into two groups with neither of the groups containing a troublesome pair.
Limits
1 ≤ T ≤ 100.
Each member name will consist of only letters and the underscore character.
Names are case-sensitive.
No pair will appear more than once in the same test case.
Each pair will contain two distinct League members.
Small dataset
1 ≤ M ≤ 10.
Large dataset
1 ≤ M ≤ 100.
Sample
#define N 2100#define M 100005#define maxn 205#define MOD 1000000000000000007int st[N],sn,n2,T,num,n;char s1[N],s2[N];vector<int> p[N];map<string,int> mymap;bool vis[N];bool DFS(int x){ if(vis[x^1]) return false; if(vis[x]) return true; vis[x] = true; st[sn++] = x; FI(p[x].size()){ if(!DFS(p[x][i])) return false; } return true;}bool sat_2(){ fill(vis,false); for(int i = 0;i<n2;i++){ if(!vis[i] ){ sn = 0; if(!DFS(i)){ FJ(sn) vis[st[j]] = false; sn = 0; if(!DFS(i^1)) return false; } } } return true;}void add_edge(int a,int b){ //printf("%d %d\n",a,b); //printf("%d %d\n",b^1,a^1); p[a].push_back(b); p[b].push_back(a); p[b^1].push_back(a^1); p[a^1].push_back(b^1);}int main(){ freopen("A-small-2-attempt0.in", "r", stdin); freopen("A-small-2-attempt0.out", "w", stdout); while(S(T)!=EOF) { for(int tcase = 1;tcase<=T;tcase++){ S(n); mymap.clear(); FI(N) p[i].clear(); num = 0; FI(n){ SS(s1);SS(s2); int x1,x2; if(mymap.count(s1)) { x1 = mymap[s1]; } else { mymap[s1] = num; x1 = num; num +=2; } if(mymap.count(s2)) { x2 = mymap[s2]; } else { mymap[s2] = num; x2 = num; num +=2; } add_edge(x1,x2^1); } n2 = num; if(sat_2()){ printf("Case #%d: Yes\n",tcase); } else { printf("Case #%d: No\n",tcase); } } } fclose(stdin); fclose(stdout); return 0;}
- Practice Round APAC test Problem A. Bad Horse 2-sat
- [Practice Round APAC test 2016]Problem A. Bad Horse(Google 2016笔试题)
- Practice Round APAC test 2017--Problem A. Lazy Spelling Bee
- Practice Round APAC test 2017——1.Problem A. Lazy Spelling Bee
- Problem A. Lazy Spelling Bee Google APAC 2017 University Test Practice Round
- Practice Round APAC test 2017--Problem B. Robot Rock Band
- Round A APAC Test 2016 Problem A. Googol String
- Round A APAC Test 2016 Problem A. Googol String
- Google APAC 2016 University Graduates Test Practice Round APAC test
- Google APAC test 2015 Round B Problem A - Password Attacker
- Round A APAC Test 2016 Problem C. gCampus 最短路
- Round A APAC Test 2016 Problem B. gCube
- Round A APAC Test 2016: Problem B. gCube
- Round C APAC Test 2017 Problem A. Monster Path
- Round B APAC Test 2017 Problem A. Sherlock and Parentheses
- Problem A. Vote Google APAC 2017 University Test Round D
- Problem B. Rain Google APAC 2017 University Test Round A
- Problem A. gRanks Google APAC 2016 University Test Round C
- hdoj5253
- OC_Notifications(通知)
- IO流笔记02
- 从零开始学习iOS开发-股票记帐本1.0(1)
- 【CF 474E】Pillars
- Practice Round APAC test Problem A. Bad Horse 2-sat
- 使用专用硬件加速深度卷积神经网络
- 风险投资与经营者 分成利润
- 正则表达式知识点汇集
- NGUI 无法刷新 shader参数的问题
- HDU 2032
- RMAN正确地删除Archivelog以及设置有备库的归档删除策略
- HDU 4086
- Head First Java 中文高清版