多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > HDU 2647 Reward(拓撲排序)

HDU 2647 Reward(拓撲排序)

來源:程序員人生   發布時間:2014-12-12 08:33:13 閱讀次數:3191次
Problem Description
Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to distribute rewards to his workers. Now he has a trouble about how to distribute the rewards.
The workers will compare their rewards ,and some one may have demands of the distributing of rewards ,just like a's reward should more than b's.Dandelion's unclue wants to fulfill all the demands, of course ,he wants to use the least money.Every work's reward will be at least 888 , because it's a lucky number.
 

Input
One line with two integers n and m ,stands for the number of works and the number of demands .(n<=10000,m<=20000)
then m lines ,each line contains two integers a and b ,stands for a's reward should be more than b's.
 

Output
For every case ,print the least money dandelion 's uncle needs to distribute .If it's impossible to fulfill all the works' demands ,print ⑴.
 

Sample Input
2 1 1 2 2 2 1 2 2 1
 

Sample Output
1777 ⑴
 

Author
dandelion


拓撲排序。。

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> typedef long long LL; using namespace std; #define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i ) #define REP( i , n ) for ( int i = 0 ; i < n ; ++ i ) #define CLEAR( a , x ) memset ( a , x , sizeof a ) const int maxn=10100; int head[maxn*2],next[maxn*2],end[maxn*2]; int in[maxn],val[maxn]; int n,m,cnt,k; void toposort() { int sum=0; k=0; queue<int>q; REPF(i,1,n) if(!in[i]) q.push(i); while(!q.empty()) { int v=q.front(); sum+=val[v]; q.pop(); k++; for(int i=head[v];i!=⑴;i=next[i]) { if(--in[end[i]]==0) { q.push(end[i]); val[end[i]]=val[v]+1; } } } if(k==n) printf("%d ",sum); else printf("⑴ "); } void add(int x,int y) { next[cnt]=head[x]; end[cnt]=y; head[x]=cnt++; } int main() { int x,y; while(~scanf("%d%d",&n,&m)) { cnt=0; REPF(i,1,n) val[i]=888; CLEAR(in,0); CLEAR(head,⑴); REP(i,m) { scanf("%d%d",&x,&y); add(y,x); in[x]++; } toposort(); } return 0; }


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 欧美激情亚洲激情 | 国产亚洲高清在线精品不卡 | 免费看成人毛片日本久久 | 欧美国一级毛片片aa | 在线播放69热精品视频 | www.自拍| 亚洲韩国日本一级二级r级 亚洲韩精品欧美一区二区三区 | 国产精品成熟老女人 | 亚洲精品网站在线观看不卡无广告 | 国产日韩精品欧美一区色 | 国产免费私拍一区二区三区 | www91在线观看 | 欧美在线看片 | 欧美在线一区二区三区不卡 | 精品一区二区三区在线观看l | 午夜在线免费观看 | 亚洲伊人成综合成人网 | 精品国产91乱码一区二区三区 | 性色在线播放 | 亚洲第一视频网 | 欧美精品18videose×性欧美 | 国产成人精品久久综合 | free欧美xxxxvideo| 欧美一级淫片免费观看 | 欧美一级视频免费看 | 三级大片网站 | 在线观看一区二区三区四区 | 亚洲国产成人久久 | 日韩欧美自拍 | 樱花aⅴ一区二区三区四区 影视精品网站入口 | 欧美小网站 | 国产精品二区高清在线 | 欧美日韩国产综合在线 | 一级欧美毛片成人 | youjizz久久| 久久久久久亚洲精品影院 | 欧美成a人片在线观看 | 国产精品免费一区二区区 | 69免费视频大片 | 欧美三级中文字幕hd | 久久久久久久久久久久久久久久久久久久 |