PersonalCorpus 版 (精华区)

1144196 Big Guava ... 10305 Accepted
0:00.000 64 2002/10/04 13:23:26.806

bool dl[100][100],used[100];

int tryit (int n)
{
    int i,j;

    for (i=0;i<n;i++) if (!used[i]) {
        for (j=0;j<n;j++) if (!used[j]) if (dl[j][i]) break;
        if (j==n) {
            for (j=0;j<n;j++) dl[i][j]=false;
            used[i]=true;
            return i;
        }
    }
    return -1;
}


void main()
{
#ifndef ONLINE_JUDGE
    freopen("c:\\0acm\\uva\\i10305","r",stdin);
    freopen("c:\\0acm\\uva\\o10305","w",stdout);
#endif

    int i,j,k,n,m;

    scanf("%d%d\n",&n,&m);
    while ((m>0)||(n>0)) {
        memset(dl,0,sizeof(dl));
        memset(used,0,sizeof(used));
        for (k=0;k<m;k++) {
            scanf("%d%d\n",&i,&j);
            dl[i-1][j-1]=true;
        }
        for (i=0;i<n;i++) {
            printf("%d",tryit(n)+1);
            if (i==n) printf("\n"); else printf(" ");
        }
        scanf("%d%d\n",&n,&m);
    }
}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.084毫秒