hdu6166 Senior Pan
Senior Pan
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1411 Accepted Submission(s): 558
The task is simple : ZKC will give Pan a directed graph every time, and selects some nodes from that graph, you can calculate the minimum distance of every pair of nodes chosen in these nodes and now ZKC only cares about the minimum among them. That is still too hard for poor Pan, so he asks you for help.
Then m lines follow. Each line contains three integers xi,yi representing an edge, and vi representing its length.1≤xi,yi≤n,1≤vi≤100000
Then one line contains one integer K, the number of nodes that Master Dong selects out.1≤K≤n
The following line contains K unique integers ai, the nodes that Master Dong selects out.1≤ai≤n,ai!=aj
5 6
1 2 1
2 3 3
3 1 3
2 5 1
2 4 2
4 3 1
3
1 3 5
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
const int maxn = ;
const ll inf = 1e17; int T,cas,n,vis[maxn],m,head[maxn],to[maxn],nextt[maxn],w[maxn],tot = ,K,a[maxn],mark[maxn];
ll d[maxn],ans = inf; struct node
{
int x;
ll len;
bool operator < (const node& a) const {
return len > a.len;
}
};
priority_queue<node> q; void add(int x,int y,int z)
{
w[tot] = z;
to[tot] = y;
nextt[tot] = head[x];
head[x] = tot++;
} ll dijkstra()
{
while (!q.empty())
{
node u = q.top();
q.pop();
int x = u.x;
ll len = u.len;
if (mark[x])
return len;
if (vis[x])
continue;
vis[x] = ;
for (int i = head[x];i;i = nextt[i])
{
int v = to[i];
if (d[v] > d[x] + w[i])
{
d[v] = d[x] + w[i];
node temp;
temp.x = v;
temp.len = d[v];
q.push(temp);
}
}
}
return inf;
} void solve()
{
for (int i = ; i < ; i++)
{
while (!q.empty())
q.pop();
memset(vis,,sizeof(vis));
memset(mark,,sizeof(mark));
memset(d,/,sizeof(d));
for (int j = ; j <= K; j++)
{
if (( << i) & a[j])
mark[a[j]] = ;
else
{
node temp;
temp.x = a[j];
temp.len = ;
d[a[j]] = ;
q.push(temp);
}
}
ans = min(ans,dijkstra());
memset(vis,,sizeof(vis));
memset(mark,,sizeof(mark));
memset(d,/,sizeof(d));
while (!q.empty())
q.pop();
for (int j = ; j <= K; j++)
{
if (( << i) & a[j])
{
node temp;
temp.len = ;
temp.x = a[j];
d[a[j]] = ;
q.push(temp);
}
else
mark[a[j]] = ;
}
ans = min(ans,dijkstra());
}
} int main()
{
scanf("%d",&T);
while (T--)
{
ans = inf;
tot = ;
memset(head,,sizeof(head));
scanf("%d%d",&n,&m);
for (int i = ; i <= m; i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
add(x,y,z);
}
scanf("%d",&K);
for(int i = ; i <= K; i++)
scanf("%d",&a[i]);
solve();
printf("Case #%d: %lld\n",++cas,ans);
} return ;
}
hdu6166 Senior Pan的更多相关文章
- 【最短路】【dijkstra】【二进制拆分】hdu6166 Senior Pan
题意:给你一张带权有向图,问你某个点集中,两两结点之间的最短路的最小值是多少. 其实就是dijkstra,只不过往堆里塞边的时候,要注意塞进去它是从集合中的哪个起始点过来的,然后在更新某个点的答案的时 ...
- hdu 6169 Senior PanⅡ Miller_Rabin素数测试+容斥
Senior PanⅡ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Pr ...
- HDU 6166 Senior Pan (最短路变形)
题目链接 Problem Description Senior Pan fails in his discrete math exam again. So he asks Master ZKC to ...
- HDU - 6166:Senior Pan(顶点集合最短路&二进制分组)
Senior Pan fails in his discrete math exam again. So he asks Master ZKC to give him graph theory pro ...
- HDU 6166.Senior Pan()-最短路(Dijkstra添加超源点、超汇点)+二进制划分集合 (2017 Multi-University Training Contest - Team 9 1006)
学长好久之前讲的,本来好久好久之前就要写题解的,一直都没写,懒死_(:з」∠)_ Senior Pan Time Limit: 12000/6000 MS (Java/Others) Memor ...
- HDU 6166 Senior Pan 二进制分组 + 迪杰斯特拉算法
Senior Pan Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Probl ...
- 2017多校第9场 HDU 6169 Senior PanⅡ 数论,DP,爆搜
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6169 题意:给了区间L,R,求[L,R]区间所有满足其最小质数因子为k的数的和. 解法: 我看了这篇b ...
- HDU 6166 Senior Pan(k点中最小两点间距离)题解
题意:n个点,m条有向边,指定k个点,问你其中最近的两点距离为多少 思路:这题的思路很巧妙,如果我们直接枚举两点做最短路那就要做C(k,2)次.但是我们换个思路,我们把k个点按照二进制每一位的0和1分 ...
- hdu 6166 Senior Pan
http://acm.hdu.edu.cn/showproblem.php?pid=6166 题意: 给出一张无向图,给定k个特殊点 求这k个特殊点两两之间的最短路 二进制分组 枚举一位二进制位 这一 ...
随机推荐
- Tree - XGBoost with parameter description
In the previous post, we talk about a very popular Boosting algorithm - Gradient Boosting Decision T ...
- .NET导出Excel之NPOI
前段时间研究过微软的Excel导出.table输出Excel,而它们也存在一些弊端: 1.对于微软的Excel导出存在一些弊端,如:需要安装Office软件.速度问题: 2.table输出Excel在 ...
- 在香港网站使用工商银行的MasterCard,工商银行所犯的低级的错误,金融安全何在
- Github二次学习
作者声明:本博客中所写的文章,都是博主自学过程的笔记,参考了很多的学习资料,学习资料和笔记会注明出处,所有的内容都以交流学习为主.有不正确的地方,欢迎批评指正. 本节课视频内容:https://www ...
- MySQL case when 使用
case when 自定义排序时的使用 根据 case when 新的 sort字段排序 case when t2.status = 4 and t2.expire_time>UNIX_TIME ...
- Vue工作原理小结
本文能帮你做什么?1.了解vue的双向数据绑定原理以及核心代码模块2.缓解好奇心的同时了解如何实现双向绑定为了便于说明原理与实现,本文相关代码主要摘自vue源码, 并进行了简化改造,相对较简陋,并未考 ...
- 撤销 git merge
由于太多人问怎么撤销 merge 了,于是 git 官方出了这份教程,表示在 git 现有的思想体系下怎么达到撤销 merge 的目标. 方法一,reset 到 merge 前的版本,然后再重做接下来 ...
- 第17次Scrum会议(10/29)【欢迎来怼】
一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/10/29 17:20~17:42,总计22min.地点:东北师 ...
- GIT团队实战
项目要求 组长博客 遇到的困难及解决办法 组员1(组长):王彬 遇到的困难 在团队任务分工的时候没有充分照顾到所有人,导致队员们的工作量不均. 现场编程时间不够 解决办法 在此对组员们表示抱歉,由于 ...
- BETA版本前冲刺准备
[团队概要] 团队项目名:小葵日记 团队名:日不落战队 队员及角色: 队员 角色 备注 安琪 前端工程师 队长 佳莹 前端工程师 智慧 后端工程师 章鹏 后端工程师 语恳 UI设计师 炜坤 前端工程师 ...