Create a gist now

Instantly share code, notes, and snippets.

#include<bits/stdc++.h>
using namespace std;
int N,cc,t[2];
bool visited[1005];
char a[1005][1005];
void dfs(int pos){
if(visited[pos])return;
visited[pos]=true;
cc++;
for(int i=0;i<N;i++)
if(a[pos][i]=='Y')
dfs(i);
}
int main(){
scanf("%d",&N);
int total=N*(N-1)/2;
for(int i=0;i<N;i++){
scanf("%s",a[i]);
for(int j=0;j<i;j++)
if(a[i][j]=='Y')total--;
}
for(int i=0;i<N;i++){
if(visited[i])continue;
cc=0;
dfs(i);
t[cc%2]++;
}
int f=(t[0]==0&&t[1]==2?0:1);
if( (t[0]==1&&t[1]==2) || total%2==f )cout<<"Taro"<<endl;
else cout<<"Hanako"<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment