http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contest-bapc-13-en.pdf

题意:给你一张无向图,t个可能的目的地,问在这t个点中哪些点的最短路中经过了g和h

思路:这是傻逼题,我直接dijstra用vector< set<int> > 保存路径, 最后再去判断下。。好像这并不是出题者想要的解法,不过时间还可以,300+ms

 #pragma comment(linker, "/STACK:1000000000")
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define MAXN 100005
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
struct Edge
{
int from, to, dist;
Edge(int from, int to, int dist):from(from), to(to), dist(dist){};
};
struct HeapNode
{
int d, u;
HeapNode(int d, int u):d(d), u(u){};
bool operator <(const HeapNode& rhs) const{
return d > rhs.d;
}
};
vector< set<int> > road[MAXN];
struct Dijstra
{
int n, m;
vector<Edge> edges;
vector<int> G[MAXN];
bool done[MAXN];
int d[MAXN];
int p[MAXN]; void init(int n){
this->n = n;
for(int i = ; i <= n; i++){
G[i].clear();
road[i].clear();
}
edges.clear();
} void AddEdge(int from, int to, int dist){
edges.push_back(Edge(from, to, dist));
m = edges.size();
G[from].push_back(m - );
} void dijstra(int s){
priority_queue<HeapNode> Q;
for(int i = ; i <= n; i++){
d[i] = INF;
}
d[s] = ;
memset(done, , sizeof(done));
Q.push(HeapNode(, s));
while(!Q.empty()){
HeapNode x = Q.top();
Q.pop();
int u = x.u;
if(done[u]) continue;
done[u] = true;
for(int i = ; i < G[u].size(); i++){
Edge& e = edges[G[u][i]];
if(d[e.to] > d[u] + e.dist){
d[e.to] = d[u] + e.dist;
road[e.to].clear();
if(road[u].empty()){
set<int> tmp;
tmp.clear();
tmp.insert(u);
road[e.to].push_back(tmp);
}
else{
for(int j = ; j < road[u].size(); j++){
road[e.to].push_back(road[u][j]);
road[e.to][j].insert(u);
}
}
p[e.to] = G[u][i];
Q.push(HeapNode(d[e.to], e.to));
}
else if(d[e.to] == d[u] + e.dist){
int w = road[e.to].size();
for(int j = ; j < road[u].size(); j++){
road[e.to].push_back(road[u][j]);
road[e.to][w + j].insert(u);
}
}
}
}
}
};
int n, m, t, g, h, s;
Dijstra p;
vector<int> res;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int T;
scanf("%d", &T);
while(T--){
scanf("%d%d%d", &n, &m, &t);
scanf("%d%d%d", &s, &g, &h);
int x, y, z;
p.init(n);
for(int i = ; i <= m; i++){
scanf("%d%d%d", &x, &y, &z);
p.AddEdge(x, y, z);
p.AddEdge(y, x, z);
}
p.dijstra(s);
res.clear();
for(int i = ; i <= t; i++){
scanf("%d", &x);
for(int j = ; j < road[x].size(); j++){
road[x][j].insert(x);
if(road[x][j].find(g) != road[x][j].end() && road[x][j].find(h) != road[x][j].end()){
res.push_back(x);
break;
}
}
}
sort(res.begin(), res.end());
int w = res.size();
for(int i = ; i < w; i++){
printf("%d ", res[i]);
}
printf("\n");
}
}

Gym - 100625D Destination Unknown 最短路的更多相关文章

  1. Codeforces Gym 100338C Important Roads 最短路+Tarjan找桥

    原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...

  2. Gym - 100338C Important Roads 最短路+tarjan

    题意:给你一幅图,问有多少条路径使得去掉该条路后最短路发生变化. 思路:先起始两点求两遍单源最短路,利用s[u] + t[v] + G[u][v] = dis 找出所有最短路径,构造新图.在新图中找到 ...

  3. 暑假集训-WHUST 2015 Summer Contest #0.2

    ID Origin Title 10 / 55 Problem A Gym 100625A Administrative Difficulties   4 / 6 Problem B Gym 1006 ...

  4. Hadoop集群模式安装出现的若干问题

    一.域名解析问题 域名解析暂时失败问题 vim /etc/sysconfig/network 查看主机名 vim etc/hosts 配置IP地址与主机名 192.168.60.132 centos ...

  5. [转]自动驾驶平台Apollo 2.5环境搭建

    原文地址:https://blog.csdn.net/jinzhuojun/article/details/80210180,转载主要方便随时查阅,如有版权要求,请及时联系. 我们知道,自动驾驶在学界 ...

  6. 【最短路】NEERC15 F Froggy Ford(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 一只青蛙跳过宽为W的河,河中游N个石头,坐标xi,yi,现在往河中间添加一个石头,使得每次跳跃的最大的距离最小 ...

  7. 【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  8. Gym 101873C - Joyride - [最短路变形][优先队列优化Dijkstra]

    题目链接:http://codeforces.com/gym/101873/problem/C 题意: 这是七月的又一个阳光灿烂的日子,你决定和你的小女儿一起度过快乐的一天.因为她真的很喜欢隔壁镇上的 ...

  9. Gym - 100625J Jailbreak 最短路+搜索

    http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...

随机推荐

  1. 《剑指Offer》——试题1:赋值运算符函数

    题目:如下类型为CMyString的声明,请为该类型添加赋值运算符函数.   class CMyString { public: CMyString(char* pData = NULL); CMyS ...

  2. UNIX系统高级编程——第六章-系统数据文件和信息-总结

    口令文件: /* The passwd structure. */ struct passwd { char *pw_name; /* Username. */ char *pw_passwd; /* ...

  3. 用centos镜像 制作本地yum源

    1.上传iso镜像 2.挂载镜像到相应目录 mkdir /yumiso #创建目录mount -t iso9660 /dev/cdrom/sr0 /yumiso #挂载镜像文件到对应目录 3.备份旧的 ...

  4. Github README.md中添加图片

    1.先把图片上传到你的项目中:然后在github网站上按路径打开图片,如下打开的图片链接: 2.复制图片的地址 3.然后在README.md写上: ![这里随便写文字](你刚复制的图片路径) 注意  ...

  5. 使用Openfire和Asmack实现IM功能,常常出现“Thread already started”的错误

    近期使用Openfire和Asmack实现Android端的IM功能,可是实际使用的过程中,常常出现"java.lang.IllegalThreadStateException:Thread ...

  6. 【Hibernate学习】 ——ORM(二)

    上篇博客主要介绍了一对一的关系,主要理解单向与双向的差别,主键关联与唯一外键关联的差别.以下继续介绍一对多与多对多关联. 一对多关联映射 一个班级相应多个学生 watermark/2/text/aHR ...

  7. poj2280--Amphiphilic Carbon Molecules(扫描线+极角排序+转换坐标)

    题目链接:id=2280">点击打开链接 题目大意:给出n个点的坐标.每一个点有一个值0或者1,如今有一个隔板(无限长)去分开着n个点,一側统计0的个数,一側统计1的个数,假设点在板上 ...

  8. Scala学习笔记及与Java不同之处总结-从Java开发者角度

    Scala与Java具有很多相似之处,但又有很多不同.这里主要从一个Java开发者的角度,总结在使用Scala的过程中所面临的一些思维转变. 这里仅仅是总结了部分两种语言在开发过程中的不同,以后会陆续 ...

  9. iOS 报错:(子线程中更新UI)This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.

    今天在写程序的时候,使用Xcode 运行工程时报出下面的错误错信息,我还以为是什么呢,好久没遇到过这样的错误了. **ProjectName[1512:778965] This application ...

  10. 9. IntelliJ Idea 集成svn 和使用

    转自:http://www.cnblogs.com/zhanghaoliang/p/6206948.html 最近公司的很多同事开始使用IntelliJ Idea,便尝试了一下,虽然快捷键与eclip ...