hdu 3342 Legal or Not(拓扑排序)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
int mat[200][200];
int ran[200];
int main()
{
    int n,m;
    int i,j,k;
    int f,t;
    while(scanf("%d%d",&n,&m),n)
    {
       int ok=1;
       memset(ran,0,sizeof(ran));
       memset(mat,0,sizeof(mat));
       for(i=0;i<m;i++)
       {
           scanf("%d%d",&f,&t);
           if(mat[f][t]==0)//???
           {
                mat[f][t]=1;
                ran[t]++;
           }
       }
       for(i=0;i<n;i++)
       {
           int flag=-1;
           if(ok==0) break;
           for(j=0;j<n;j++)
           {
               if(ran[j]==0)
               {
                   flag=j;
                   ran[j]=-1;
                   break;
               }
           }
           if(flag==-1)
           {
               ok=0;
               break;
           }
           for(j=0;j<n;j++)
           {
               if(mat[flag][j]>0) ran[j]--;
           }
       }
       if(ok==1) printf("YES\n");
       else printf("NO\n");
    }
    return 0;
}
时间: 2024-08-15 09:20:45

hdu 3342 Legal or Not(拓扑排序)的相关文章

hdu 3342 Legal or Not - 拓扑排序

ACM-DIY is a large QQ group where many excellent acmers get together. It is so harmonious that just like a big family. Every day,many "holy cows" like HH, hh, AC, ZT, lcc, BF, Qinz and so on chat on-line to exchange their ideas. When someone has

hdu 3342 Legal or Not 拓扑排序判断环。 现在的我,除了刷水题,,还能干什么

Legal or Not Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4960    Accepted Submission(s): 2270 Problem Description ACM-DIY is a large QQ group where many excellent acmers get together. It is

HDU 1258 确定比赛名次 &amp;&amp;HDU 3342 Legal or Not 【临接表+拓扑排序】

HDU 1258 链接:click here HDU 3342 链接:click here 题意: 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14142    Accepted Submission(s): 5667 Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,

[ACM] hdu 3342 Legal or Not (拓扑排序)

Legal or Not Problem Description ACM-DIY is a large QQ group where many excellent acmers get together. It is so harmonious that just like a big family. Every day,many "holy cows" like HH, hh, AC, ZT, lcc, BF, Qinz and so on chat on-line to excha

HDU 3213 Box Relations(拓扑排序构造)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3231 题意:有n个长方体,四种限制条件.(1)I x y x和y有相交:(2)X/Y/Z  x y x的最大X/Y/Z坐标小于y的最大X/Y/Z.构造出这样的n个长方体. 思路:首先,XYZ三个方向是可以分开考 虑的.那么我们可以一个个分别求解.将每个长方体拆成左上角右下角两个点,我们假设现在考虑X方向,也即是一个长方体对应两个X方向的点,共2*n个点, 边<i,j>表示i小于j,那么首先有边&l

HDU 2647 Reward(图论-拓扑排序)

Reward Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to distribute rewards to his workers. Now he has a trouble about how to distribute the rewards. The workers will compare their rewards ,a

HDU 2467 Reward(逆拓扑排序)

拓扑排序的变形,逆序建图就好了 Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3951    Accepted Submission(s): 1203 Problem Description Dandelion's uncle is a boss of a factory. As the spring festival

HDU 4324 Triangle LOVE (拓扑排序)

Triangle LOVE Problem Description Recently, scientists find that there is love between any of two people. For example, between A and B, if A don't love B, then B must love A, vice versa. And there is no possibility that two people love each other, wh

HDU 3342 Legal or Not(拓扑排序判环)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3342 题目: Problem Description ACM-DIY is a large QQ group where many excellent acmers get together. It is so harmonious that just like a big family. Every day,many "holy cows" like HH, hh, AC, ZT, lc

HDU 3342 Legal or Not(拓扑排序判断成环)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3342 题目大意:n个点,m条有向边,让你判断是否有环. 解题思路:裸题,用dfs版的拓扑排序直接套用即可. 代码: 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int N=1e2+5; 6 7 int n,m; 8 int vis[N];