BestCoder Round #25
2016-07-31 23:14
288 查看
刚进行过图论的练习,试着用图论的方法做了一下,挺有意思的!
1001题
->点我传送<-
未完待续……
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; }
未完待续……
相关文章推荐
- [BestCoder] Round #25 1001 - Harry and Magical Computer | HDU 5154
- hdu 5154 Harry and Magical Computer(BestCoder Round #25)
- BestCoder Round #25 A,B
- [BestCoder Round #25 1003]Harry and Christmas tree
- [BestCoder Round #25 1002]Harry And Magic Box 解题报告
- BestCoder Round #25 1002 Harry And Magic Box [dp]
- 【BestCoder Round #25】A(拓扑排序,找环)
- hdu 5082 Love(Bestcoder Round #15)
- BestCoder Round #18题解
- BestCoder Round #28
- 【HDU5586 BestCoder Round 64 (div1)A】【贪心 最大连续子串】Sum 区间函数值变换使得数列权值和最大
- BestCoder #Valentine's Day Round 1001 || hdu 5174
- 【HDU5635 BestCoder Round 74 (div2)A】【贪心 暴力】LCP Array 相邻后缀最大相同前缀 输出字符串方案数
- BestCoder Round #75 - King's Phone
- BestCoder Round #14 03 Harry And Math Teacher (线段树)
- hdu 5083 Instruction(Bestcoder Round #15)
- BestCoder Round 59 (HDOJ 5500) Reorder the Books
- BestCoder Round #20 部分题解(A,B,C)(hdu5123,5124,5125)
- BestCoder Round #92
- 【HDU5213 BestCoder Round 39D】【莫队算法+容斥】Lucky 两个区间各选一个数使得和为K的方案数