链接

[https://vjudge.net/contest/281085#problem/D]

题意

有n个任务,有M个对先后顺序

然你输出最后的完成任务的顺序,有多种可能输出一种即可

分析

裸的拓扑排序,需要队列和vector

代码

#include<iostream>
#include<string.h>
#include<vector>
#include<queue>
using namespace std;
int n,m,a,b;
int in[110];
int main(){
//freopen("in.txt","r",stdin);
while(cin>>n>>m&&(n+m)){
vector<int> v1[110];
memset(in,0,sizeof(in));
for(int i=1;i<=m;i++)
{
cin>>a>>b;
v1[a].push_back(b);
in[b]++;
}
queue<int> q;
vector<int> v2; for(int i=1;i<=n;i++)
if(in[i]==0) q.push(i);
//cout<<q.size()<<endl;
while(!q.empty()){
int p=q.front();
q.pop();
v2.push_back(p);
for(int i=0;i<v1[p].size();i++){
in[v1[p][i]]--;
if(in[v1[p][i]]==0)
q.push(v1[p][i]);
}
}
for(int i=0;i<v2.size();i++)
cout<<v2[i]<<' ';
cout<<endl;
}
return 0;
}

Ordering Tasks的更多相关文章

  1. Ordering Tasks(拓扑排序+dfs)

    Ordering Tasks John has n tasks to do. Unfortunately, the tasks are not independent and the executio ...

  2. [SOJ] Ordering Tasks

    1940. Ordering Tasks Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description John has n task ...

  3. UVA.10305 Ordering Tasks (拓扑排序)

    UVA.10305 Ordering Tasks 题意分析 详解请移步 算法学习 拓扑排序(TopSort) 拓扑排序的裸题 基本方法是,indegree表示入度表,vector存后继节点.在tops ...

  4. 拓扑排序(Topological Order)UVa10305 Ordering Tasks

    2016/5/19 17:39:07 拓扑排序,是对有向无环图(Directed Acylic Graph , DAG )进行的一种操作,这种操作是将DAG中的所有顶点排成一个线性序列,使得图中的任意 ...

  5. Ordering Tasks UVA - 10305 图的拓扑排序

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  6. M - Ordering Tasks(拓扑排序)

    M - Ordering Tasks Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Descri ...

  7. [拓扑排序]Ordering Tasks UVA - 10305

    拓扑排序模版题型: John has n tasks to do.Unfortunately, the tasks are not independent and the execution of o ...

  8. UVa 10305 - Ordering Tasks (拓扑排序裸题)

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  9. Ordering Tasks 拓扑排序

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  10. UVA10305:Ordering Tasks(拓扑排序)

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

随机推荐

  1. mssql sqlserver 取消数值四舍五入的方法分享

    摘要: 下文讲述使用round sql函数,对数值型数据进行舍入操作 实验环境:sqlserver 2008 转自: http://www.maomao365.com/?p=6454 最近接到用户需求 ...

  2. CentOS7中启动Tomcat后,8080端口不能被外部访问的解决办法。

    运行:/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

  3. spreadJs 自动换行功能和自动增高行高

    var styleTmp = sheet.getStyle(displayRowIndex, displayColumnIndex, GcSpread.Sheets.SheetArea.viewpor ...

  4. 自动获取svn的版本号

    需求 在做打包时,需要获取本地svn仓库的版本号,如下所示: 下面是我试过的几种做法 SubWCRev 使用SubWCRev.exe(TortoiseSVN自带的小工具),用法简单,但获取到的版本号有 ...

  5. 搭建windows测试环境的步骤

     步骤:1.JDK安装 2.配置好JDK环境变量3.Tomcat安装4.将war包放在Tomcat的发布目录中webapps中,5.conf>server.xml里面设置默认解压,unpackW ...

  6. February 12th, 2018 Week 7th Monday

    One man's fault is another man's lesson. 前车之覆,后车之鉴. We make mistakes every day, large or small, fail ...

  7. CSS鼠标悬浮DIV后显示DIV外的按钮

    昨天写样式遇到个问题,如何让鼠标悬浮DIV后,显示DIV外的按钮,可以点击到按钮. 效果如下: 问题: 在DIV hover时候将按钮设为display: block,这是很直接的想法,但是这有个问题 ...

  8. Go学习笔记05-指针

    目录 参数传递 var a int = 2 var pa *int = &a *pa = 3 fmt.Println(a) Go语言中 指针不能运算 参数传递 不像C++.Java.Pytho ...

  9. static 关键字和类的加载顺序

      静态变量在类加载时初始化,而非静态变量在创建对象时初始化.static关键字修饰的变量就是静态变量. 子类继承父类,子类在生成对象的时候,先初始化父类的成员变量,接着执行父类的构造器,完成父类的初 ...

  10. UVA12265-Selling Land(细节处理)

    Problem UVA12265-Selling Land Accept: 309  Submit: 3231Time Limit: 3000 mSec Problem Description Inp ...