hdu 2647
来源:互联网 发布:优化设计 英文 编辑:程序博客网 时间:2024/04/29 03:22
http://acm.hdu.edu.cn/showproblem.php?pid=2647
#include <iostream>#include <cstdio>#include <queue>#include <cstring>#define MM 10005using namespace std;int inde[MM];int add[MM]; //每人要加的。struct Node{ int data; Node *next; Node():data(0),next(0){}}*e[MM];void addEdage(int u,int v){ Node *t =new Node; t->data=v; t->next=e[u]; e[u]=t;}void init(int n){ memset(e,0,sizeof(e)); memset(inde,0,sizeof(inde)); int i; for(i=0;i<=n;i++) add[i]=888;}int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { int i,a,b; init(n); for(i=0;i<m;i++) { scanf("%d%d",&a,&b); addEdage(b,a); //注意是反向的 inde[a]++; } queue<int> q; for(i=1;i<=n;i++) { if(inde[i]==0) { q.push(i); } } int sum=0; int count=0; while(!q.empty()) { int t=q.front(); q.pop(); count++; sum=sum+add[t]; Node *hh; for(hh=e[t];hh;hh=hh->next) { if(--inde[hh->data]==0) { q.push(hh->data); add[hh->data]=add[t]+1; //注意点 } } } if(count!=n) printf("-1\n"); else printf("%d\n",sum); } return 0;}
- hdu 2647
- HDU 2647
- hdu 2647
- hdu 2647
- hdu 2647 Reward
- hdu 2647 (拓扑)
- hdu 2647 Reward
- hdu 2647 Reward
- HDU-2647拓扑排序
- HDU 2647 Reward
- hdu 2647 Reward
- hdu 2647 Reward
- hdu 2647 拓扑排序
- hdu 2647 拓扑排序
- hdu-2647 Reward
- 拓扑排序 HDU 2647
- hdu 2647 Reward
- HDU 2647 Reward
- 中文乱码
- Firefox扩展版Hello World + 构建火狐插件官方样例npruntime步骤
- JavaScript学习总结
- Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned'
- 友善comtest.c串口编译
- hdu 2647
- CVS
- AdapterView的使用
- SVN
- Linux下网桥式防火墙的构建与实现
- 说一说java反射(1)
- ubuntu12.04完美安装snort
- Ubuntu下静态IP的设置(VirtualBOX)
- 记录