#include <iostream>
#include <stdio.h>
#include <string.h>
#define clr(x) memset(x,0,sizeof(x))
#define maxn 1000000 + 5
using namespace std;
struct node
{
int to;
int next;
}q[maxn];
int head[maxn];
int tot;
int n,m;
void add( int s, int u)
{
q[tot].to = u;
//每个结点存一条边,next表示与当前边起点一样的另一条边在弄的数组中的位置。to表示这条边的终点.
//head[i]表示从i出发的点的链表的第一个点在node数组中的位置。
q[tot].next = head[s];//当前结点指向以前的头结点
cout<<" to "<<q[tot].to<<" next "<<q[tot].next<<endl;
head[s] = tot++;//当前结点变为头结点
cout<<"head "<<s << " "<<head[s]<<endl;
}
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)
{
cout<<"---head"<<i<<endl;
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);
}
}
int main()
{
int a,b,i;
while(scanf("%d %d", &n, &m),n)
{
clr(head);
clr(instack);
clr(dfn);
ti = sn = 0;
tot = 1;
top = -1;
while( m-- )
{
scanf("%d %d",&a, &b);
add(a,b);
}
for( int i = 1; i<=n; i++)
{
if( dfn[i] == 0)
{
cout<<i<<endl;
tarjan(i);
}
}
if(sn > 1)
printf("No\n");
else
printf("Yes\n");
for( int i = 1; i<= n; i++)
cout<<head[i]<<endl;
}
return 0;
}
#include <stdio.h>
#include <string.h>
#define clr(x) memset(x,0,sizeof(x))
#define maxn 1000000 + 5
using namespace std;
struct node
{
int to;
int next;
}q[maxn];
int head[maxn];
int tot;
int n,m;
void add( int s, int u)
{
q[tot].to = u;
//每个结点存一条边,next表示与当前边起点一样的另一条边在弄的数组中的位置。to表示这条边的终点.
//head[i]表示从i出发的点的链表的第一个点在node数组中的位置。
q[tot].next = head[s];//当前结点指向以前的头结点
cout<<" to "<<q[tot].to<<" next "<<q[tot].next<<endl;
head[s] = tot++;//当前结点变为头结点
cout<<"head "<<s << " "<<head[s]<<endl;
}
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)
{
cout<<"---head"<<i<<endl;
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);
}
}
int main()
{
int a,b,i;
while(scanf("%d %d", &n, &m),n)
{
clr(head);
clr(instack);
clr(dfn);
ti = sn = 0;
tot = 1;
top = -1;
while( m-- )
{
scanf("%d %d",&a, &b);
add(a,b);
}
for( int i = 1; i<=n; i++)
{
if( dfn[i] == 0)
{
cout<<i<<endl;
tarjan(i);
}
}
if(sn > 1)
printf("No\n");
else
printf("Yes\n");
for( int i = 1; i<= n; i++)
cout<<head[i]<<endl;
}
return 0;
}