直接上代码吧

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int
m,n,map[][],degree[];
int
topo()
{

int
i,j,k,mark;
for
(i=;i<m;i++)
{

mark=;
for
(j=;j<m;j++)
{

if
(degree[j]==)
{

mark=;
degree[j]=-;
break
;
}
}

if
(!mark)
return
;
for
(k=;k<m;k++)
{

if
(map[j][k])
degree[k]--;
}
}

return
;
}

int
main()
{

int
a,b,i,j;
while
(scanf("%d%d",&m,&n)!=EOF)
{

if
(m==&&n==) break;
memset(map,,sizeof(map));
memset(degree,,sizeof(degree));
for
(i=;i<n;i++)
{

scanf("%d%d",&a,&b);
if
(!map[a][b])
{

map[a][b]=;
degree[b]++;
}
}

int
t=topo();
if
(t)
printf("YES\n");
else

printf("NO\n");
}

return
;
}

hdu 3342 拓扑模板题的更多相关文章

  1. HDU 2138 Miller-Rabin 模板题

    求素数个数. /** @Date : 2017-09-18 23:05:15 * @FileName: HDU 2138 miller-rabin 模板.cpp * @Platform: Window ...

  2. HDU 3342 拓扑排序模板

    Legal or Not Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. hdu 3342 拓扑排序 水

    好久没切题  先上水题! 拓扑排序! 代码: #include<iostream> #include<cstdio> #include<cstring> using ...

  4. HDU 1392 凸包模板题,求凸包周长

    1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...

  5. HDU 2586 (LCA模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2586 题目大意:在一个无向树上,求一条链权和. 解题思路: 0 | 1 /   \ 2      3 ...

  6. HDU 2082 母函数模板题

    找单词 Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status De ...

  7. HDU 2087 kmp模板题

    s为主串 t为模板串 求t的nextt 加const #include<stdio.h> #include<string.h> #include<algorithm> ...

  8. 【网络流#3】hdu 1532 - Dinic模板题

    输入为m,n表示m条边,n个结点 记下来m行,每行三个数,x,y,c表示x到y的边流量最大为c 这道题的模板来自于网络 http://blog.csdn.net/sprintfwater/articl ...

  9. poj 1251 poj 1258 hdu 1863 poj 1287 poj 2421 hdu 1233 最小生成树模板题

    poj 1251  && hdu 1301 Sample Input 9 //n 结点数A 2 B 12 I 25B 3 C 10 H 40 I 8C 2 D 18 G 55D 1 E ...

随机推荐

  1. qt 添加程序插件目录

    QApplication::addLibraryPath(QApplication::applicationDirPath()); QApplication::addLibraryPath(QAppl ...

  2. redis配置注意事项(适合于较大配置)

    根据官方的建议,redis-server的相关配置建议如下,但是有些并不合适,LZ会进行说明(如果redis使用的内存还不到1GB,或者大量qps还不到1000的应用,这已经淘汰了99%的应用,很多配 ...

  3. Vuex 通俗版教程告诉你Vuex怎么用

    写在文前: 最近一直在用vue开发项目,写来写去就是那么些方法,对于简单的项目一些常用的vue方法足以解决,但是涉及到页面状态,权限判断等一些复杂的传值,vuex是必须的.对于vuex也运用一段时间, ...

  4. javascript的promise

  5. python 中的一些基础算法:递归/冒泡/选择/插入

    递归算法 如果一个函数包含了对自己的调用,那么这个函数就是递归的. 比如我们计算下1-7乘法的计算: def func(n): if n ==1 : return 1 return n*func(n- ...

  6. MySQL5.7查看数据存储位置

    在MySQL客户端执行如下命令查看MySQL的数据存放位置: mysql> show global variables like "%datadir%"; +-------- ...

  7. 第十九章 动态URL权限控制——《跟我学Shiro》

    目录贴:跟我学Shiro目录贴 用过Spring Security的朋友应该比较熟悉对URL进行全局的权限控制,即访问URL时进行权限匹配:如果没有权限直接跳到相应的错误页面.Shiro也支持类似的机 ...

  8. Vue项目过程中遇到的小问题

    1.给router-link添加点击事件 <router-link to="" @click.native=""></router-link& ...

  9. linux服务器常用密令

    1. 什么是linux服务器load average? Load是用来度量服务器工作量的大小,即计算机cpu任务执行队列的长度,值越大,表明包括正在运行和待运行的进程数越多.参考资料:http://e ...

  10. RabbitMQ的安装(Windows环境下)

    在使用RabbitMQ之前,先知道什么是AMQP,AMQP 即 Advanced Message Queuing Protocol ,又叫高级消息队列协议,是应用层协议的一个开放标准,其主要特征是面向 ...