Gym - 100625D Destination Unknown 最短路
题意:给你一张无向图,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 最短路的更多相关文章
- Codeforces Gym 100338C Important Roads 最短路+Tarjan找桥
原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...
- Gym - 100338C Important Roads 最短路+tarjan
题意:给你一幅图,问有多少条路径使得去掉该条路后最短路发生变化. 思路:先起始两点求两遍单源最短路,利用s[u] + t[v] + G[u][v] = dis 找出所有最短路径,构造新图.在新图中找到 ...
- 暑假集训-WHUST 2015 Summer Contest #0.2
ID Origin Title 10 / 55 Problem A Gym 100625A Administrative Difficulties 4 / 6 Problem B Gym 1006 ...
- Hadoop集群模式安装出现的若干问题
一.域名解析问题 域名解析暂时失败问题 vim /etc/sysconfig/network 查看主机名 vim etc/hosts 配置IP地址与主机名 192.168.60.132 centos ...
- [转]自动驾驶平台Apollo 2.5环境搭建
原文地址:https://blog.csdn.net/jinzhuojun/article/details/80210180,转载主要方便随时查阅,如有版权要求,请及时联系. 我们知道,自动驾驶在学界 ...
- 【最短路】NEERC15 F Froggy Ford(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
题目链接: http://codeforces.com/gym/100851 题目大意: 一只青蛙跳过宽为W的河,河中游N个石头,坐标xi,yi,现在往河中间添加一个石头,使得每次跳跃的最大的距离最小 ...
- 【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- Gym 101873C - Joyride - [最短路变形][优先队列优化Dijkstra]
题目链接:http://codeforces.com/gym/101873/problem/C 题意: 这是七月的又一个阳光灿烂的日子,你决定和你的小女儿一起度过快乐的一天.因为她真的很喜欢隔壁镇上的 ...
- Gym - 100625J Jailbreak 最短路+搜索
http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...
随机推荐
- 【CS-4476-project 6】Deep Learning
AlexNet / VGG-F network visualized by mNeuron. Project 6: Deep LearningIntroduction to Computer Visi ...
- 紫书 习题8-19 UVa 1312 (枚举技巧)
这道题参考了https://www.cnblogs.com/20143605--pcx/p/4889518.html 这道题就是枚举矩形的宽, 然后从宽再来枚举高. 具体是这样的, 先把所有点的高度已 ...
- HDU 4725 The Shortest Path in Nya Graph
he Shortest Path in Nya Graph Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged o ...
- 洛谷 P1524 十字绣
P1524 十字绣 题目背景 考古学家发现了一块布,布上做有针线活,叫做“十字绣”,即交替地在布的两面穿线. 题目描述 布是一个n*m的网格,线只能在网格的顶点处才能从布的一面穿到另一面.每一段线都覆 ...
- Android清单文件具体解释(六) ---- <activity>节点的属性
1.android:allowTaskReparenting android:allowTaskReparenting是一个任务调整属性,它表明当这个任务又一次被送到前台时,该应用程序所定义的Acti ...
- 10gR2 rac怎样重跑root.sh ?
原文博客链接地址:10gR2 rac怎样重跑root.sh ? 前几天遇到一客户的10205 rac,出现LMD进程IPC SEND TIMEOUT问题. 准备深入研究下Oracle RAC 的LMO ...
- 2014 Unity3d大会的部分总结
一.项目开发.管理和公布策略 1. 四大准则 a. 美术的资源量 b. 美术规范,要依据开发什么样的游戏制定统一的规范,这样尽可能的形成统一的规范.然后程序要协助美 ...
- 大话html5应用与app应用优缺点
在这个app横飞的年代,对于整个产品研发团队来讲,高速的迭代,爆炸式的功能追加已经成为了互联网行业的时代标签,以小时甚至分钟为单位的进度度量成为了常态.在这个市场大环境下,浪里淘沙的不单单是商业模式. ...
- dom4j组装xml 以及解析xml
dom4j组装xml 以及解析xml: 1.下载dom4j的jar包,地址:https://dom4j.github.io/ 2.java代码: package test; import java.i ...
- Django分页和查询参数的问题
查询是通过get的方式,之前没有分页之前,url是这样的: http://hostname/search?query=port%3A8080 那么我的想法是如果分页了. 1,不带page参数了.nex ...