代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
const long M=210;
long head[M],to[M*M],Next[M*M],cnt;
long link[M],vis[M],n;
void init_edge(){
memset(head,-1,sizeof(head));
memset(link,0,sizeof(link));
cnt=0;
}
void add_edge(long u,long v){
Next[cnt]=head[u]; to[cnt]=v; head[u]=cnt++;
}
long dfs(long u){
for (long i=head[u];i!=-1;i=Next[i]){
long v=to[i];
if (vis[v]) continue; vis[v]=1;
if (!link[v] || dfs(link[v])){
link[v]=u;
return 1;
}
}
return 0;
}
int main(){
while (~scanf("%d",&n)){
init_edge();
for (long i=1;i<=n;++i){
char c; getchar();
for (long j=1;j<=n;++j){
scanf("%c",&c);
if (c=='U') add_edge(i,j);
}
}
long ans=0;
for (long i=1;i<=n;++i){
memset(vis,0,sizeof(vis));
if (dfs(i)) ans++;
}
if (ans==n) printf("YES\n");
else printf("NO\n");
}
return 0;
}