HDU 5695 Gym Class
拓扑排序。
#include<cstdio>
#include <iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std; const int maxn = + ;
int T, n, m;
bool flag[maxn]; struct Edge
{
int u, v;
int nx;
}e[maxn];
int tot;
int head[maxn];
int cnt[maxn]; int L[maxn];
int f; void init()
{
tot = ;
memset(cnt, , sizeof cnt);
memset(head, -, sizeof head);
memset(flag, , sizeof flag);
} void add(int a, int b)
{
++tot;
e[tot].u = a; e[tot].v = b; e[tot].nx = head[a];
head[a] = tot;
} void read()
{
scanf("%d%d", &n, &m);
for (int i = ; i <= m; i++)
{
int u, v; scanf("%d%d", &u, &v);
add(u, v);
cnt[v]++;
}
} void Sort()
{
priority_queue<int>Q; f = ;
for (int i = ; i <= n; i++) if (cnt[i] == ) Q.push(i);
while (!Q.empty())
{
int h = Q.top(); Q.pop();
L[f++] = h;
for (int i = head[h]; i != -; i = e[i].nx)
{
cnt[e[i].v]--;
if (cnt[e[i].v] == ) Q.push(e[i].v);
}
} long long ans = L[];
long long Min = L[];
for (int i = ; i < f; i++)
{
Min = min(Min,(long long) L[i]);
ans = ans + Min;
} printf("%lld\n", ans); } int main()
{
scanf("%d", &T);
while (T--)
{
init();
read();
Sort();
}
return ;
}
HDU 5695 Gym Class的更多相关文章
- HDU 5695 Gym Class 拓扑排序
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5695 题解: 求出字典序最大的拓扑序.然后把求好的数列翻转过来就是满足条件的数列,然后模拟求一下va ...
- HDU 5695 Gym Class && 百度之星 初赛 1006
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5695 本文链接:http://www.cnblogs.com/Ash-ly/p/5515234.htm ...
- HDU - 5695 Gym Class 【拓扑排序】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5695 思路 给定一些关系 进行拓扑排序 但是有一个要求 对于哪些没有确切的位置的点 要按照ID大小 I ...
- HDU 5695 ——Gym Class——————【贪心思想,拓扑排序】
Gym Class Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- 题解报告:hdu 5695 Gym Class(拓扑排序)
题目链接:acm.hdu.edu.cn/showproblem.php?pid=5695 Problem Description 众所周知,度度熊喜欢各类体育活动.今天,它终于当上了梦寐以求的体育课老 ...
- HDU - 5695 Gym Class (优先队列+拓扑排序)
题意:有N个人,每个人的ID为1~N,部分同学A不希望部分同学B排在他之前,排好队之后,每个同学会找出包括自己在内的前方所有同学的最小ID,作为自己评价这堂课的分数.在满足这个前提的情况下,将N个人排 ...
- 2016"百度之星" - 初赛(Astar Round2A)HDU 5695 拓扑排序+优先队列
Gym Class Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- hdu 5695 百度熊教体育 拓扑排序 好题
Gym Class Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- HDU 5965 Gym Class 贪心+toposort
分析:就是给一些拓补关系,然后求最大分数,所以贪心,大的越靠前越好,小的越靠后越好 剩下的就是toposort,当然由于贪心,所以使用优先队列 #include <iostream> #i ...
随机推荐
- Handler引起的内存泄露
一般我都写handler的时候是这样的: public class MyActivity extends Activity{ private final Handler myHandler = n ...
- 不需要用任何辅助工具打包Qt应用程序
不需要用任何辅助工具打包Qt应用程序.方法如下: 生成release文件后,双击里面的exe文件,会弹出一个对话框,里面提示缺少哪一个DLL文件, 然后根据该文件名到你安装QT软件的目录下的/b ...
- 最简单的教程:在Ubuntu操作系统里安装Docker
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互之间不会有任何 ...
- 1《数学之美》第1章 文字和语言 vs 数字和信息
1<数学之美>第1章 文字和语言 vs 数字和信息
- System.currentTimeMillis()与日期之间的相互转换
System.currentTimeMillis()与日期 之间是可以相互转换的,大多数Android开发者都知道 通过 SimpleDateFormat dateformat = new Simpl ...
- CentOS 7上修改主机名
如何在CentOS 7上修改主机名 在Cent ...
- Linux常用的操作指令
1.pwd-显示当前所在位置 2.cd-进入当前目录 3.cd..-返回上一级目录 4..ls命令参数选项有很多,ls也是经常使用到的命令.如果不清楚命令的使用方式可以直接 ls --help来查看 ...
- Deep_into_iris
具体ipynb文件请移步Github #各种所需要的库函数首先加载 import numpy as np import pandas as pd import matplotlib.pyplot as ...
- AndroidStudio连不上天天模拟器
问题:天天模拟器经常无法被Android Studio读取出来: 解决方法:手动连接它的端口: 方法一:找到Android\SDK\platform-tools目录,在当前目录下打开命令行窗口(shi ...
- 【php】查看扩展的版本
php --ri [扩展名称] 例如: php --ri mongodb mongodb MongoDB support => enabled MongoDB extension version ...