hdu3342 Legal or Not(简单拓扑排序判定)
来源:互联网 发布:linux 如何安装xampp 编辑:程序博客网 时间:2024/09/21 11:19
思路:拓扑排序模板题
#include<cstdio>#include<cstring>#include<vector>#include<queue>using namespace std;const int maxn=100+10;int n,m;vector<int> G[maxn];int in[maxn];bool topo(){ queue<int> Q; int sum=0; for(int i=0;i<n;i++)if(in[i]==0) Q.push(i); while(!Q.empty()) { int u=Q.front(); Q.pop(); sum++; for(int i=0;i<G[u].size();i++) { int v=G[u][i]; if(--in[v]==0) Q.push(v); } } return sum==n;}int main(){ while(scanf("%d%d",&n,&m)==2&&n) { memset(in,0,sizeof(in)); for(int i=0;i<n;i++) G[i].clear(); for(int i=0;i<m;i++) { int u,v; scanf("%d%d",&u,&v); G[u].push_back(v); in[v]++; } printf("%s\n",topo()?"YES":"NO"); } return 0;}
0 0
- hdu3342 Legal or Not(简单拓扑排序判定)
- hdu3342 Legal or Not 拓扑排序
- Legal or Not(hdu3342拓扑排序)
- hdu3342 Legal or Not (拓扑排序+邻接矩阵)
- hdu3342 Legal or Not---拓扑排序
- HDU3342 Legal or Not 【拓扑排序】
- HDU3342 Legal or Not(拓扑排序)
- hdu3342 Legal or Not(拓扑排序)
- hdu3342 Legal or Not【拓扑排序】
- HDU3342:Legal or Not(拓扑排序)
- HDU3342---Legal or Not(拓扑排序。)
- HDU 3342 Legal or Not(简单拓扑排序判定)
- HDU3342 Legal or Not 解题报告--拓扑排序
- hdu3342 Legal or Not(拓扑排序,判环)
- HDU3342 Legal or Not【拓扑排序】【链式前向星】
- HDU3342 Legal or Not 拓扑排序判环
- HDU3342---Legal or Not
- HDU3342-Legal or Not
- 理解Hadoop分布式文件系统HDFS(二)
- 【总结】深插浅出重拾Linux
- 为已有的web project项目加入maven支持,并使用myeclipse的插件.
- sp<> wp<>-Android中定义了两种智能指针强指针sp和弱指针wp
- RUST语法
- hdu3342 Legal or Not(简单拓扑排序判定)
- 圆形ImageView系列(一)-----Xfermode+View
- LightOJ--1149--Factors and Multiples(二分图好题)
- Android自定义属性限制
- ActionInvoker
- 如何在Java中对MongoDB按日期进行查询统计
- 〖原创〗使用Docker过程中注意事项之壹(文章末尾有彩蛋!)
- 【转】Android LockScreen admin API sample code
- iOS开发中@property的属性weak nonatomic strong readonly等介绍