题目

传送门:QWQ

分析

最短路显然,但不好搞地位等级。。。。。

地位等级不好搞?那么就暴力。。

枚举我们允许的地位等级,跑最短路。

所以$ n^2logn $出100什么鬼啊,很有迷惑性啊

还有4篇cf没补博客好慌啊

代码

细节不少,WA了好几发

//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
const int maxn=, INF=1e9;
struct Edge{
int u,v,dis;
};
vector<Edge> edges; vector<int> G[maxn];
void Addedge(int u,int v,int dis){
edges.push_back((Edge){u,v,dis}); G[u].push_back(edges.size()-);
}
int l[maxn], L, R, val[maxn];
struct HeapNode{
int x,dis;
bool operator < (const HeapNode& a) const{ return dis>a.dis; }
};
priority_queue<HeapNode> que;
int d[maxn],vis[maxn], n;
int dijkstra(int s ){
if(l[s]<L || l[s]>R) return val[s];
memset(d,,sizeof(d)); memset(vis,,sizeof(vis));
d[s]=; que.push((HeapNode){s,}); //vis[s]=1;
while(!que.empty()){
HeapNode x=que.top(); que.pop();
if(vis[x.x]) continue; vis[x.x]=;
int u=x.x;
for(int i=;i<G[u].size();i++){
Edge& e=edges[G[u][i]];
if(l[e.v]>=L && l[e.v]<=R && d[e.v]>d[u]+e.dis){
d[e.v]=d[u]+e.dis;
que.push((HeapNode){e.v,d[e.v]});
}
}
}
int ans=1e9;
for(int i=;i<=n;i++){
ans=min(ans,d[i]+val[i]);
}
return ans;
}
int main(){
int m; scanf("%d%d",&m,&n);
int x, q=,b,c;
for(int i=;i<=n;i++){
scanf("%d%d%d",&val[i],&l[i],&x);
while(x--){
scanf("%d%d",&b,&c); Addedge(i,b,c);
}
q=max(q,l[i]);
}
int ans=INF;
for(int i=;i<=max(q-m,n);i++){
L=i; R=i+m;
ans=min(ans,dijkstra());
}
printf("%d\n",ans);
return ;
}

【POJ】1062 昂贵的聘礼 (最短路)的更多相关文章

  1. POJ - 1062 昂贵的聘礼(最短路Dijkstra)

    昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u SubmitStatus Descr ...

  2. POJ 1062 昂贵的聘礼 最短路 难度:0

    http://poj.org/problem?id=1062 #include <iostream> #include <cstring> #include <queue ...

  3. POJ 1062 昂贵的聘礼 最短路+超级源点

    Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长降低 ...

  4. poj 1062 昂贵的聘礼 最短路 dijkstra

    #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...

  5. 最短路(Dijkstra) POJ 1062 昂贵的聘礼

    题目传送门 /* 最短路:Dijkstra算法,首先依照等级差距枚举“删除”某些点,即used,然后分别从该点出发生成最短路 更新每个点的最短路的最小值 注意:国王的等级不一定是最高的:) */ #i ...

  6. POJ 1062 昂贵的聘礼(图论,最短路径)

    POJ 1062 昂贵的聘礼(图论,最短路径) Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女 ...

  7. poj 1062 昂贵的聘礼 (dijkstra最短路)

    题目链接:http://poj.org/problem?id=1062 昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

  8. 最短路POJ 1062 昂贵的聘礼

    C - 昂贵的聘礼 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit St ...

  9. POJ 1062 昂贵的聘礼 (最短路)

    昂贵的聘礼 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/M Description 年轻的探险家来到了一个印第安部落里.在那里 ...

  10. poj 1062 昂贵的聘礼 (有限制的最短路)

    昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 56594   Accepted: 17083 Descripti ...

随机推荐

  1. codevs 2216 行星序列 线段树+延迟标记(BZOJ 1798)

    2216 行星序列  时间限制: 2 s  空间限制: 256000 KB     题目描述 Description “神州“载人飞船的发射成功让小可可非常激动,他立志长大后要成为一名宇航员假期一始, ...

  2. Tornado教程目录

    第一章:引言 第二章:表单和模板 第三章:模板扩展 第四章:数据库 第五章:异步Web服务 第六章:编写安全应用 第七章:外部服务认证 第八章:部署Tornado

  3. Spring Cloud组件

    Spring Cloud Eureka Eureka负责服务的注册于发现,Eureka的角色和 Zookeeper差不多,都是服务的注册和发现,构成Eureka体系的包括:服务注册中心.服务提供者.服 ...

  4. $ocLazyLoad

    博客:http://zhidao.baidu.com/link?url=1eODexxXPsl2gy4UsRnfIqPJnzFrzFk2JJad-cjWDiyCKkb4qxS8scvxoMRqM0Fw ...

  5. 解决mysql安装报错:无法启动此程序,因为计算机丢失MSVCP120.dll

    问题一: 因为装的是新系统,所以遇到mysql启动报错:无法启动此程序,因为计算机丢失MSVCP120.dll 后来参考这篇文章https://blog.csdn.net/huacode/articl ...

  6. hdu2177威佐夫博弈

    输的话输出0,赢就输出1并且输出第一步走后的数目 威佐夫博弈判断胜负 原理及常见题型求法: http://blog.csdn.net/y990041769/article/details/216940 ...

  7. Bitwise Equations

    Problem Description You are given two positive integers X and K. Return the K-th smallest positive i ...

  8. bzoj2163

    题解: 拆点网络流 然后用总和-最大流 代码: #include<iostream> #include<cstring> #include<cstdio> #inc ...

  9. MIPS 汇编指令学习

    MIPS 寄存器 MIPS comes with 32 general purpose registers named $0. . . $31Registers also have symbolic ...

  10. java-IO-基本输出输入流

    / 标准输入输出流: 直接类名调用 一经创建无法改变 public static final PrintStream err “标准”错误输出流. public static final InputS ...