模板。。。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define clr(x)memset(x,0,sizeof(x))
const int maxn=100010;
struct node{
int to;
int next;
}q[100010];
int head[100010];
int tot;
int n,m;
void add(int s,int u){
q[tot].to=u;
q[tot].next=head[s];
head[s]=tot++;
}
int dfn[maxn];
int low[maxn];
int stack[maxn];
int ti,sn,top;
bool instack[maxn];
void tarjan(int u){
dfn[u]=low[u]=++ti;
stack[++top]=u;
instack[u]=true;
int k,i;
for(i=head[u];i;i=q[i].next){
k=q[i].to;
if(dfn[k]==0) {
tarjan(k);
if(low[u]>low[k])low[u]=low[k];
}
else if(instack[k]&&low[u]>dfn[k])
low[u]=dfn[k];
}
if(low[u]==dfn[u]){
sn++;
do{
k=stack[top--];
instack[k]=false;
}while(k!=u);
}
}
void init(){
clr(head);
clr(instack);
clr(dfn);
ti=sn=0; //ti时间戳 sn强连通分量序号
tot=1;
top=-1;
}
int main(){
int a,b,i;
while(scanf("%d%d",&n,&m)!=EOF){
if(n==0&&m==0)break;
init();
while(m--){
scanf("%d%d",&a,&b);
add(a,b);
}
for(i=1;i<=n;i++)
if(dfn[i]==0)tarjan(i);
if(sn>1)printf("No\n");
else printf("Yes\n");
}
return 0;
}