HDU 1285 确定比赛名次 拓扑排序
来源:互联网 发布:淘宝上怎么找发票 编辑:程序博客网 时间:2024/06/06 04:26
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=1285
思路
输入的数据一定有解:拓扑排序,优先取出编号小的点。
#include<cstdio>#include<queue>#include<iostream>#include<functional>#include<vector>#include<map>#include<cstring>#include<string>#include<set>#include<stack>#include<algorithm>#define cle(a) memset(a,0,sizeof(a))#define inf(a) memset(a,0x3f,sizeof(a))#define ll long long#define Rep(i,a,n) for(int i=a;i<=n;i++)using namespace std;#define INF2 9223372036854775807llconst int INF = ( 2e9 ) + 2;const ll maxn = 510;vector<int> g[maxn];int In[maxn];void topsort(int n){ priority_queue<int,vector<int>,greater<int> > q; for(int i=1;i<=n;i++) if(In[i]==0)q.push(i); int cnt=0; while(!q.empty()) { int u=q.top();q.pop(); for(int i=0,L=g[u].size();i<L;i++) { int v=g[u][i]; In[v]--; if(In[v]==0) q.push(v); } if(cnt!=n-1) printf("%d ",u); else printf("%d\n",u); cnt++; }}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { memset(In,0,sizeof(In)); for(int i=0;i<=n;i++)g[i].clear(); for(int i=0;i<m;i++) { int u,v; scanf("%d%d",&u,&v); g[u].push_back(v); In[v]++; } topsort(n); }}
阅读全文
0 0
- HDU 1285 拓扑排序 确定比赛名次
- HDU 1285 拓扑排序-- 确定比赛名次
- hdu 1285 确定比赛名次(拓扑排序)
- HDU 1285 确定比赛名次 拓扑排序
- 【HDU】1285 确定比赛名次 拓扑排序
- HDU【1285】确定比赛名次---拓扑排序
- HDU-1285--确定比赛名次 (拓扑排序)
- 【拓扑排序】HDU 1285--- 确定比赛名次
- hdu 1285 确定比赛名次 拓扑排序
- hdu 1285 确定比赛名次 拓扑排序
- hdu 1285 确定比赛名次 拓扑排序
- HDU 1285 确定比赛名次 拓扑排序
- HDU 1285 - 确定比赛名次 <拓扑排序>
- 拓扑排序:hdu 1285 确定比赛名次
- 拓扑排序 HDU 1285 确定比赛名次
- Hdu 1285 确定比赛名次,拓扑排序
- hdu 1285 确定比赛名次(拓扑排序)
- hdu 1285 确定比赛名次(拓扑排序)
- 在谷歌浏览器安装json格式化插件
- 建立保持时间的介绍与分析
- oracle时间函数
- miniui -- 当前页export to excel
- TF库的使用
- HDU 1285 确定比赛名次 拓扑排序
- Docker Registry
- linux解压war包的命令
- 文件的输入和输出
- Intent&IntentFilter
- Java算法之二分查找算法
- phpstorm 2017.1 激活
- Spring是什么
- jquery层次选择器:空格 > next + nextAll ~ siblings