Description

一个无向图,到一个点之前需要先到其他点,求从第一个点到第 \(n\) 点最短时间.

Sol

拓扑+Dijkstra.

跑Dijkstra的时候加上拓扑序...

用两个数组表示 到该点的最短路和到拓扑中最大的距离,入堆的时候需要对两个取 \(max\) .

Code

#include<cstdio>
#include<cstring>
#include<utility>
#include<vector>
#include<queue>
#include<iostream>
using namespace std; #define mpr make_pair
typedef long long LL;
typedef pair< LL,int > pr;
const int N = 3005; int n,m;
vector<pr> g[N];vector<int> h[N];
bool b[N];int p[N];LL d[N],w[N];
priority_queue<pr,vector<pr>,greater<pr> > q; inline int in(int x=0,char ch=getchar()){ while(ch>'9' || ch<'0') ch=getchar();
while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x; }
void Dijkstra(int s){
memset(d,0x3f,sizeof(d)),memset(b,0,sizeof(b));
d[s]=w[s]=0;q.push(mpr(0,s));
for(int x;!q.empty();){
x=q.top().second,q.pop();if(b[x]) continue;b[x]=1;
LL tmp=max(d[x],w[x]);
for(int i=0;i<g[x].size();i++){
LL l=g[x][i].first;int v=g[x][i].second;
if(tmp+l < d[v]){
d[v]=tmp+l;
if(p[v] == 0) q.push(mpr(max(d[v],w[v]),v));
}
}for(int i=0,v;i<h[x].size();i++){
v=h[x][i],w[v]=max(w[v],tmp),p[v]--;
if(p[v] == 0) q.push(mpr(max(d[v],w[v]),v));
}
}
}
int main(){
n=in(),m=in();
for(int i=1,u,v,l;i<=m;i++) u=in(),v=in(),l=in(),g[u].push_back(mpr(l,v));
for(int i=1,l,u;i<=n;i++) for(l=in();l--;) u=in(),h[u].push_back(i),++p[i];
Dijkstra(1);
cout<<max(d[n],w[n])<<endl;
return 0;
}

  

BZOJ 1922: [Sdoi2010]大陆争霸的更多相关文章

  1. bzoj 1922 [Sdoi2010]大陆争霸(最短路变形)

    Description 在一个遥远的世界里有两个国家:位于大陆西端的杰森国和位于大陆东端的 克里斯国.两个国家的人民分别信仰两个对立的神:杰森国信仰象征黑暗和毁灭 的神曾·布拉泽,而克里斯国信仰象征光 ...

  2. bzoj 1922: [Sdoi2010]大陆争霸【dijskstra】

    d[u]为u被几个节点保护,d1[u]为最早到u的时间,d2[u]为u的最早可进入时间(保护点都被打下来了的时候),然后最终最早进入时间就是max(d1[u],d2[u]),把这个作为权值放进小根堆, ...

  3. BZOJ 1922: [Sdoi2010]大陆争霸 Dijkstra

    Code: #include <queue> #include <vector> #include <cstdio> #include <cstring> ...

  4. 洛谷 P2446 [SDOI2010]大陆争霸 解题报告

    P2446 [SDOI2010]大陆争霸 题目背景 在一个遥远的世界里有两个国家:位于大陆西端的杰森国和位于大陆东端的克里斯国.两个国家的人民分别信仰两个对立的神:杰森国信仰象征黑暗和毁灭的神曾·布拉 ...

  5. AC日记——[SDOI2010]大陆争霸 洛谷 P3690

    [SDOI2010]大陆争霸 思路: dijkstra模板: 代码: #include <bits/stdc++.h> using namespace std; #define maxn ...

  6. bzoj1922 [SDOI2010]大陆争霸 分层图

    问题描述 幻想历8012年5月12日深夜,斯普林·布拉泽降下神谕:“Trust me, earn eternal life.”克里斯军团士气大增.作为克里斯军团的主帅,你决定利用这一机会发动奇袭,一举 ...

  7. 【bzoj1922】 Sdoi2010—大陆争霸

    http://www.lydsy.com/JudgeOnline/problem.php?id=1922 (题目链接) 题意 一张无向图,每个节点被k个节点保护,想要走到一个节点当且仅当它不被保护.你 ...

  8. BZOJ1922 [Sdoi2010]大陆争霸

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...

  9. BZOJ1922:[SDOI2010]大陆争霸(最短路)

    Description 在一个遥远的世界里有两个国家:位于大陆西端的杰森国和位于大陆东端的 克里斯国.两个国家的人民分别信仰两个对立的神:杰森国信仰象征黑暗和毁灭 的神曾·布拉泽,而克里斯国信仰象征光 ...

随机推荐

  1. HTML学习笔记——box

    1> HTML写法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...

  2. 使用github和hexo搭建博客

    title: How to build your blog by Hexo in github Welcome to huihuang's blog,you will find what you ex ...

  3. GLSL Debugger的姿势

    https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/OpenGLShaderBuilder ...

  4. js获取锚点名称 #

    var thisId = window.location.hash; alert(thisId); 输出 #2

  5. php Hash Table(三) Hash Table初始化

    HashTable初始化,在使用HashTable之前要先执行初始化,下边就看看初始化时都做了什么, Zend/zend_hash.c static const Bucket *uninitializ ...

  6. PHPCMS 模板制作标签

    内容模块: 栏目调用1: {pc:content action="category" catid="0" num="25" siteid=& ...

  7. python mysql

    mysql Linux 安装mysql: apt-get install mysql-server 安装python-mysql模块:apt-get install python-mysqldb Wi ...

  8. Intellij Idea中运行tomcat 报內存溢出 解决方案 火龙战士 火龙战士

    在Run/Debug configuration 的你要运行行的tomcat里面的 vm options里面输入 -server -XX:PermSize=128M -XX:MaxPermSize=2 ...

  9. spring的PathMatchingResourcePatternResolver-通配符的Resource查找器

    PathMatchingResourcePatternResolver是一个通配符的Resource查找器,包括: /WEB-INF/*-context.xml com/mycompany/**/ap ...

  10. 脱离 Spring 实现复杂嵌套事务,之一(必要的概念)

    事务传播行为种类 Spring在TransactionDefinition接口中规定了7种类型的事务传播行为, 它们规定了事务方法和事务方法发生嵌套调用时事务如何进行传播: 表1事务传播行为类型 事务 ...