HDU1285 确定比赛名次 拓扑排序
2013-10-10 18:59
549 查看
#include<iostream> #include<cstdio> #include<list> #include<algorithm> #include<cstring> #include<string> #include<queue> #include<stack> #include<map> #include<vector> #include<cmath> #include<memory.h> #include<set> #define ll long long #define LL __int64 const ll INF=9999999999999; using namespace std; #define M 400000100 #define inf 0xfffffff //vector<int,int> G[20002]; //vector<pair<int,int>> ::iterator iter; //map<ll,int>mp; //map<ll,int>::iterator p; int mp[1012][1012]; int vis[2012]; int n,m; void clear() { memset(mp,0,sizeof(mp)); memset(vis,0,sizeof(vis)); } void detal(int x) { for(int i=1;i<=n;i++) mp[x][i]=0; } void topsort() { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(vis[j]) continue; bool flag=true; for(int k=1;k<=n;k++) { if(mp[k][j])//这里判断j的入度 { flag=false; break; } } if(flag) { if(i==1) printf("%d",j); else printf(" %d",j); vis[j]=1;//标记j detal(j); break; } } } } int main(void) { while(scanf("%d %d",&n,&m)==2) { clear(); int a,b; for(int i=0;i<m;i++) { scanf("%d %d",&a,&b); mp[a][b]=1; } topsort(); puts(""); } }
相关文章推荐
- hdu1285 确定比赛名次 拓扑排序学习 待补完
- hdu1285 确定比赛名次(拓扑排序)
- 【拓扑排序】 hdu1285 确定比赛名次
- hdu1285确定比赛名次 拓扑排序之1285普通方法
- HDU1285 确定比赛名次(拓扑排序模板)
- [hdu1285]确定比赛名次(拓扑排序)
- hdu1285 确定比赛名次(拓扑排序)
- hdu1285 确定比赛名次(拓扑排序多种方法)
- hdu1285 确定比赛名次【拓扑排序】
- HDU1285 确定比赛名次(拓扑排序)
- hdu1285 确定比赛名次 (拓扑排序)
- HDU1285 确定比赛名次(拓扑排序)
- HDU1285确定比赛名次(拓扑排序)
- HDU1285 确定比赛名次【拓扑排序】【优先队列】
- HDU1285 确定比赛名次(拓扑排序)
- hdu1285 确定比赛名次 (简单拓扑排序)
- HDU1285 确定比赛名次 【拓扑排序】
- HDU1285:确定比赛名次(拓扑排序)
- HDU1285确定比赛名次(拓扑排序)
- hdu1285 确定比赛名次(拓扑排序多种方法)