BestCoder Round #25
来源:互联网 发布:warframe重置端口 编辑:程序博客网 时间:2024/05/27 20:50
刚进行过图论的练习,试着用图论的方法做了一下,挺有意思的!
1001题
->点我传送<-
#include<iostream>#include<cstdio>#include<cstring>#include<queue>using namespace std;const int maxn=10005;const int maxm=105;int du[maxm];vector<int>G[maxn];queue <int> q;bool vis[maxm];int n,m;void dfs(){ memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++){ if(du[i]==0){ q.push(i); vis[i]=true; } } while(!q.empty()){ int u=q.front();q.pop(); for(int i=0;i<G[u].size();i++){ int v=G[u][i]; if(!vis[v]){ du[v]--; if(du[v]==0){ q.push(v); vis[v]=true; } } } }}int main(){ while(~scanf("%d%d",&n,&m)){ memset(du,0,sizeof(du)); for(int i=1;i<=n;i++) G[i].clear(); for(int i=0;i<m;i++){ int a,b; scanf("%d%d",&a,&b); G[b].push_back(a); du[a]++; } dfs(); int flag=0; for(int i=1;i<=n;i++){ if(!vis[i]){ flag=1; break; } } if(flag) puts("NO"); else puts("YES"); } return 0;}
未完待续……
0 0
- BestCoder Round #25
- BestCoder Round #25 A,B
- BestCoder Round #3 BestCoder Sequence
- bestcoder round #1
- BestCoder round #1
- BestCoder Round #1
- 【索引】BestCoder Round #2
- BestCoder Round #2
- 【索引】BestCoder Round #3
- BestCoder Round #3
- BestCoder Round #3 小记
- BestCoder Round #4 题解
- BestCoder Round #6
- BestCoder Round #8
- Bestcoder Round #9
- BestCoder Round #9
- BestCoder Round #13(前两题)
- BestCoder Round #14
- 4.USB摄像头驱动框架分析
- 基于HTML5之APP购物车实现
- 剑指offer第9题:斐波纳西数列
- poj Musical Theme 后缀数组
- 仿网易新闻的顶部导航指示器
- BestCoder Round #25
- PAT-A 1023. Have Fun with Numbers
- 更新UI的四种方式分析
- Eclipse 启动优化问题(详细)
- IOS开发 core data 简单使用和注意
- Java类装载器研究
- 博弈小结
- 北大学习总结
- 线程池的大小应该设为多少