分析:就是给一些拓补关系,然后求最大分数,所以贪心,大的越靠前越好,小的越靠后越好

剩下的就是toposort,当然由于贪心,所以使用优先队列

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long LL;
const int N=1e5+;
const int INF=0x3f3f3f3f;
const LL mod=1e9+;
priority_queue<int>q;
struct Edge{
int v,next;
}edge[N];
int head[N],tot;
void add(int u,int v){
edge[tot].v=v;
edge[tot].next=head[u];
head[u]=tot++;
}
int d[N];
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--){
// printf("Case #%d:\n",++cas);
int n,m;
scanf("%d%d",&n,&m);
memset(head,-,sizeof(head)),tot=;
memset(d,,sizeof(d));
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
add(u,v);++d[v];
}
while(!q.empty())q.pop();
for(int i=;i<=n;++i)
if(!d[i])q.push(i);
LL ans=;int cur=-;
while(!q.empty()){
int u=q.top();
q.pop();
if(cur==-)cur=u;
else cur=min(cur,u);
ans+=cur;
for(int i=head[u];~i;i=edge[i].next){
int v=edge[i].v;
--d[v];
if(!d[v])q.push(v);
}
}
printf("%I64d\n",ans);
}
return ;
}

HDU 5965 Gym Class 贪心+toposort的更多相关文章

  1. HDU 4442 Physical Examination(贪心)

    HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...

  2. HDU 5695 ——Gym Class——————【贪心思想,拓扑排序】

    Gym Class Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  3. hdu-5695 Gym Class(贪心+拓扑排序)

    题目链接: Gym Class Time Limit: 6000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) ...

  4. HDU 5835 Danganronpa (贪心)

    Danganronpa 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5835 Description Chisa Yukizome works as ...

  5. HDU 5821 Ball (贪心)

    Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...

  6. HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))

    扫雷 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...

  7. hdu 4004 (二分加贪心) 青蛙过河

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂 ...

  8. Saving HDU(hdu2111,贪心)

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. HDU - 5695 Gym Class 【拓扑排序】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5695 思路 给定一些关系 进行拓扑排序 但是有一个要求 对于哪些没有确切的位置的点 要按照ID大小 I ...

随机推荐

  1. Java 类加载机制 ClassLoader Class.forName 内存管理 垃圾回收GC

    [转载] :http://my.oschina.net/rouchongzi/blog/171046 Java之类加载机制 类加载是Java程序运行的第一步,研究类的加载有助于了解JVM执行过程,并指 ...

  2. jquery bind()方法与live()方法的区别

    jquery bind() 方法和 live() 方法都可以绑定元素事件. <!DOCTYPE html> <html> <head> <meta chars ...

  3. uva10943

    递推  还是比较容易的 /************************************************************************* > Author: ...

  4. 编写你的第一个 Django 程序 第2部分

    原地址:http://django-chinese-docs.readthedocs.org/en/latest/intro/tutorial02.html 本教程上接 教程 第1部分 . 我们将继续 ...

  5. win8系统中PL/SQL Developer连接Oracle出现的问题

    注意:所有软件最后不要安装在program files (x86)下  PL/SQL Developer显示Not logged on 以管理员的身份打开PL/SQL Developer 2.   t ...

  6. Injection Attacks-Log 注入

    日志注入(也称日志文件注入) 很多应用都维护着一系列面向授权用户.通过 HTML 界面展示的日志,因而成为了攻击者的首要目标,这些攻击者试图伪装其他攻击.误导日志读者,甚至对阅读和分析日志监测应用的用 ...

  7. 几款开源的图形界面库(GUI Libraries)

    SmartWin++ 遵循BSD许可协议的C++ GUI库,建立在Windows API之上,但仍可以通过使用WineLib在Linux/xNix上使用.也支持Pocket PC和基于Windows ...

  8. android 从系统相册获取一张图片

    package net.viralpatel.android.imagegalleray; import android.app.Activity; import android.content.In ...

  9. MyEclipse server窗口 Could not create the view: An unexpected exception was thrown 错误解决

    MyEclipse 打开后有时候莫名的在server窗口里抛出“Could not create the view: An unexpected exception was thrown”错误,解决办 ...

  10. Android工具:延展图片NinePatch

    NinePatch能够对.png图片进行处理,生成一个.9.png格式的图片,图像拉伸操作时,图片就会有失真,而.9.png是Android里所支持的一种特殊的图片格式,可以实现部分拉伸. 制作图片方 ...