ch追妹

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 152    Accepted Submission(s): 99


Problem Description
n个点的一张无向图,ch站在a点,ch要追的妹子站在b点。r_clover为了让ch安心训练,要阻止ch追妹。ch每走一步,r_clover就会挖断一条路。ch和r_clover均采用最优策略,问ch能不能追到妹子
 

Input
第一行为数据组数T(T≤10)。
每组数据的第一行为四个数 n,m,a,b(1≤a,b≤n≤20; 1≤m≤80),分别表示点数,边数,ch的位置,妹子的位置。
之后m行,每行两个数 u,v(1≤u,v≤n),表示u,v之间有一条无向边。数据保证没有重边和自环(即不会出现u到u的边,也不会出现两条u到v的边)。
 

Output
对每组数据输出一行,如果ch能够成功追妹,输出chhappy,否则输出chsad。
 

Sample Input
2 2 1 1 2 1 2 3 2 1 3 1 2 2 3
 

Sample Output
chhappy chsad
 

仔细考虑你会发现,除非先手在第一步直接到,否则的话后手总有办法砍断他想要走的路。


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main() {
	int t;
	scanf("%d", &t);
	while(t--) {
		int n, m, a, b, st, en, flag = 0;
		scanf("%d%d%d%d", &n, &m, &a, &b);
		for(int i = 0; i < m; i++) {
			scanf("%d%d", &st, &en);
			if(st == a && en == b || st == b && en == a) {
				flag = 1;
			}
		}
		if(flag)
		 puts("chhappy");
		else
		 puts("chsad");
	}
	return 0;
}