# 【floyd】 HRBUST 2037 Find Your Teacher

## Description

You just finished your exam, you felt terrible because you might fail the exam. But your teacher was so kind that he might let you pass the lesson if you called him and begged for passing. Unfortunately, you didn’t have your teacher’s phone number! You began to ask whoever probably had the number, if they didn’t have, they would ask their classmates. Would you finally get the number?

## Input

The first line contains an integer T (1 <= T <= 20), indicates the number of test cases.
For each test case, the first line is two positive integers, n (n <= 50), m (m <= 2000). n is the number of people who will appear in the problem, you are indexed as 1 and your teacher is indexed as n.

Then m lines follows, each line contains two integers x, y (1 <= x, y <= n), means x have the phone number of y.

## Output

For each test case, if you could finally got your teacher’s number, output “^_^”, “T_T” the otherwise.

2
5 5
1 2
1 3
2 3
2 4
4 5
4 3
1 2
3 4
4 1

^_^

T_T

## Source

“尚学堂杯”哈尔滨理工大学第六届程序设计竞赛

## AC代码

#include<bits/stdc++.h>
using namespace std;

bool ans;

void solve(void)
{
std::ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
memset(ans,false,sizeof ans);
int n,m;
cin>>n>>m;
for(int i = 1 ; i <= m ; i++)
{
int f,t;
cin>>f>>t;
ans[f][t] = true;
}
for(int k = 1 ; k <= n ; k++)
{
for(int i = 1 ; i <= n ; i++)
{
for(int j = 1 ; j <=n ; j++)
{
if(ans[i][k]==true&&ans[k][j]==true)
ans[i][j] = true;
}
}
}
if(ans[n]==true) cout<<"^_^"<<endl;
else cout<<"T_T"<<endl;
}
}

int main(void)
{
solve();
return 0;
}

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客 