题意

给出一些任务的优先级别 将这些任务进行的时间 进行先后排序

思路

拓扑排序

将所以有先后关系的任务都连一条边

然后每次 输出 度为0 的任务

每次把 以这个任务为弧的边 都取消 相对应任务的度也-1

再循环

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss; const double PI = acos(-1.0);
const double E = exp(1);
const double eps = 1e-30; const int INF = 0x3f3f3f3f;
const int maxn = 1e2 + 5;
const int MOD = 1e9 + 7; int G[maxn][maxn];
int degree[maxn];
int v[maxn]; int n, m; vector <int> ans; int Count; void dfs()
{
for (int i = 1; i <= n; i++)
{
if (degree[i] == 0 && v[i] == 0)
{
Count++;
ans.pb(i);
v[i] = 1;
for (int j = 1; j <= n; j++)
{
if (G[i][j])
{
G[i][j] = 1;
degree[j]--;
}
}
}
}
if (Count != n)
dfs();
} int main()
{
while (scanf("%d%d", &n, &m) && (n || m))
{
CLR(G);
CLR(degree);
CLR(v);
int x, y;
for (int i = 0; i < m; i++)
{
scanf("%d%d", &x, &y);
G[x][y] = G[y][x] = 1;
degree[y]++;
}
ans.clear();
Count = 0;
dfs();
vector <int>::iterator it;
for (it = ans.begin(); it != ans.end(); it++)
{
if (it != ans.begin())
printf(" ");
printf("%d", (*it));
}
cout << endl;
}
}

UVA - 10305 【拓扑排序】的更多相关文章

  1. UVa 10305 (拓扑排序) Ordering Tasks

    题意: 经典的拓扑排序.有n个任务,然后某些任务必须安排在某些任务前面完成,输出一种满足要求的序列. 分析: 拓扑排序用离散里面的话来说就是将偏序关系拓展为全序关系.我们将“小于”这种关系看做一条有向 ...

  2. 【紫书】Ordering Tasks UVA - 10305 拓扑排序:dfs到底再输出。

    题意:给你一些任务1~n,给你m个数对(u,v)代表做完u才能做v 让你给出一个做完这些任务的合理顺序. 题解:拓扑排序版题 dfs到底再压入栈. #define _CRT_SECURE_NO_WAR ...

  3. Uva 10305 拓扑排序

    题意: 给定n个点,与m条边, 给出他们的拓扑排序. 分析: 拓扑排序可以有两种做法, 第一种是dfs, 每次都找到某一个点的终点, 然后加入序列末尾, 正在访问的标记为-1, 访问过的标记为1, 未 ...

  4. uva 10305 拓扑排序裸题

    https://vjudge.net/problem/UVA-10305 目前没学dfs做法,用的队列做法,每次找到一个入度为零的点出队后更新其他点,再加入入度为零的点直到查找完毕,这个题目显然一定有 ...

  5. uva 1423 拓扑排序

    刘书上例题  拓扑排序 #include <cstdio> #include <cstdlib> #include <cmath> #include <map ...

  6. UVa 1572 (拓扑排序) Self-Assembly

    题意: 有n种正放形,每种正方形的数量可视为无限多.已知边与边之间的结合规则,而且正方形可以任意旋转和反转,问这n中正方形是否可以拼成无限大的图案. 分析: 首先因为可以旋转和反转,所以可以保证在拼接 ...

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

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

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

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

  9. Uva 10305 - Ordering Tasks 拓扑排序基础水题 队列和dfs实现

    今天刚学的拓扑排序,大概搞懂后发现这题是赤裸裸的水题. 于是按自己想法敲了一遍,用queue做的,也就是Kahn算法,复杂度o(V+E),调完交上去,WA了... 于是检查了一遍又交了一发,还是WA. ...

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

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

随机推荐

  1. Scut游戏服务器引擎6.1.5.6发布,直接可运行,支持热更新

    1. 增加exe版(console),web版本(IIS)的游戏服宿主程序 2. 增加Model支持脚本化,实现不停服更新 3. 增加Language支持脚本化 4. 修改Sns与Pay Center ...

  2. Drawable 添加过滤色,改变图片颜色

    /** * 更改图片颜色 * @param drawable * @param color * @return */ public Drawable getDrawable(Drawable draw ...

  3. tomcat使用安全及CVE-2017-12615

    tomcat安全情报的收集 1.首先定期查看官网各个版本存在的安全漏洞公告: http://tomcat.apache.org/security.html 2.去各大漏洞网站查看漏洞披露信息 看几个漏 ...

  4. GLSL 基础量定义 【转】

    转载:http://blog.csdn.net/misol/article/details/7658949   GLSL语法跟C语言非常相似: 1.数据类型: GLSL包含下面几种简单的数据类型 fl ...

  5. 亿图图示专家V7破解版

    “破解文件”目录下的三个文件拷贝出来复制到安装目录下即可: 下载链接地址: http://cloud.suning.com/cloud-web/share/link.htm?sk=718100ef90 ...

  6. Predicate与filter

    转: http://blog.csdn.net/michaellufhl/article/details/6329823 怎么根据某些条件来过滤Collection的元素?我们可以在循环里面判断元素是 ...

  7. GraphMatrix::BFS广度优先搜索

    查找某一结点的邻居: virtual int firstNbr(int i) { return nextNbr(i, n); } //首个邻接顶点 virtual int nextNbr(int i, ...

  8. 《学习bash》笔记--调试shell程序

    在shell中,最简单的调试助手时输出语句echo,能够通过把很多echo语句放到代码中进行调试,但必须花费足够的时间以定位 要查看的信息.可能必须通过很多的输出才干发现要查找的信息. 1.set选项 ...

  9. 【Python】随机漫步

    创建Randomwalk()类 我们将使用Python来生成随机漫步数据,再使用matplotlib以引入瞩目的方式将这些数据呈现出来 首先创建类Randomwalk() from random im ...

  10. MySQL数据库 常用命令

    1.MySQL常用命令 create database name;创建数据库 use databasename;选择数据库 drop database name 直接删除数据库,不提醒 show ta ...