CodeForcesGym 100753A A Journey to Greece
A Journey to Greece
This problem will be judged on CodeForcesGym. Original ID: 100753A
64-bit integer IO format: %I64d Java class name: (Any)


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int maxn = ;
struct arc {
int to,cost,next;
arc(int x = ,int y = ,int z = -) {
to = x;
cost = y;
next = z;
}
} e[maxn*];
int head[maxn],hs[maxn],tot,N,P,M,G,T;
void add(int u,int v,int cost) {
e[tot] = arc(v,cost,head[u]);
head[u] = tot++;
}
priority_queue<pii,vector< pii >,greater< pii > >q;
int d[][maxn];
bool done[maxn];
void dijkstra(int S) {
while(!q.empty()) q.pop();
int s = hs[S];
memset(d[s],0x3f,sizeof d[s]);
q.push(pii(d[s][S] = ,S));
memset(done,false,sizeof done);
while(!q.empty()) {
int u = q.top().second;
q.pop();
if(done[u]) continue;
done[u] = true;
for(int i = head[u]; ~i; i = e[i].next) {
if(d[s][e[i].to] > d[s][u] + e[i].cost) {
d[s][e[i].to] = d[s][u] + e[i].cost;
q.push(pii(d[s][e[i].to],e[i].to));
}
}
}
}
int city[],ttime[],dp[<<][][];
int main() {
int u,v,w;
while(~scanf("%d%d%d%d%d",&N,&P,&M,&G,&T)) {
memset(head,-,sizeof head);
bool zero = false;
for(int i = tot = ; i < P; ++i) {
scanf("%d%d",city + i,ttime + i);
hs[city[i]] = i;
if(city[i] == ) zero = true;
}
for(int i = ; i < M; ++i) {
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
for(int i = ; i < P; ++i) dijkstra(city[i]);
if(!zero){
hs[] = P;
dijkstra();
}
memset(dp,0x3f,sizeof dp);
for(int i = ; i < P; ++i){
dp[<<i][i][] = d[hs[]][city[i]] + ttime[i];
dp[<<i][i][] = T + ttime[i];
}
int st = (<<P);
for(int i = ; i < st; ++i){
for(int j = ; j < P; ++j){
if(((i>>j)&) == ) continue;
for(int k = ; k < P; ++k){
if((i>>k)&) continue;
dp[i|(<<k)][k][] = min(dp[i|(<<k)][k][],dp[i][j][] + d[j][city[k]] + ttime[k]);
dp[i|(<<k)][k][] = min(dp[i|(<<k)][k][],dp[i][j][] + T + ttime[k]);
dp[i|(<<k)][k][] = min(dp[i|(<<k)][k][],dp[i][j][] + d[j][city[k]] + ttime[k]);
}
}
}
bool wtx = false,poss = false;
for(int i = ; i < P && !wtx; ++i){
if(dp[st-][i][] + d[i][] <= G) wtx = true;
if(dp[st-][i][] + T <= G) poss = true;
if(dp[st-][i][] + d[i][] <= G) poss = true;
}
if(wtx) puts("possible without taxi");
else if(poss) puts("possible with taxi");
else puts("impossible");
}
return ;
}
CodeForcesGym 100753A A Journey to Greece的更多相关文章
- 2015 German Collegiate Programming Contest (GCPC 15) + POI 10-T3(12/13)
$$2015\ German\ Collegiate\ Programming\ Contest\ (GCPC 15) + POI 10-T3$$ \(A.\ Journey\ to\ Greece\ ...
- CodeForcesGym 100502K Train Passengers
Train Passengers Time Limit: 1000ms Memory Limit: 524288KB This problem will be judged on CodeForces ...
- CF721C. Journey[DP DAG]
C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard input ou ...
- POJ2488A Knight's Journey[DFS]
A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 41936 Accepted: 14 ...
- 关于Hellas和Greece
一直以来我就好奇,为什么希腊的中文名字“希腊”和英文名字”Greece”听起来都不像(就像“德国”不像“Germany”一样),而且,为什么在很多体育比赛中看到希腊运动员的衣服上都是“Hellas”, ...
- CF #374 (Div. 2) C. Journey dp
1.CF #374 (Div. 2) C. Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...
- POJ2488-A Knight's Journey(DFS+回溯)
题目链接:http://poj.org/problem?id=2488 A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Tot ...
- codeforces 721C C. Journey(dp)
题目链接: C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...
- A Knight's Journey 分类: POJ 搜索 2015-08-08 07:32 2人阅读 评论(0) 收藏
A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35564 Accepted: 12119 ...
随机推荐
- HTML5移动Web开发
1. 响应式web设计 说到这个,移动开发面对的屏幕尺寸那叫一个丰富,其中安卓阵营就够让人头痛的.我们在PC端常用的两种布局方式就是固定布局和弹性布局,前者设置一个绝大多数电脑能正常显示的固定宽度居中 ...
- C头文件中尖括号与双引号的区别及编译搜索顺序
这两天被问到一个很有意思的问题:C头文件中尖括号与双引号有什么区别,以前只大约知道 <> 常用在系统库文件,"" 常用在自定义的借口文件中,那具体在gcc编译搜索过程中 ...
- phpAnalysis调试接口
phpAnalysis是一款轻量级非侵入式PHP应用性能分析器,适用于开发.测试及生产环境部署使用,方便开发及测试工程师诊断性能问题: 通过tideways收集PHP程序单步运行过程中所有的函数调用时 ...
- loadrunner乱码解决
对于Virtual User Generator,本机编码方式为GB2312,GBK,GB18030,因此要修改为utf-8 1.录制过程产生的乱码解决方法: 在tool→recording opti ...
- hihocoder #1698 假期计划 (排列组合+费马小定理+乘法逆元)
Description 小Ho未来有一个为期N天的假期,他计划在假期中看A部电影,刷B道编程题.为了劳逸结合,他决定先拿出若干天看电影,再拿出若干天刷题,最后再留若干天看电影.(若干代指大于0) 每 ...
- Java泛型Object和?区别
在写spark streamming读取kafka latest offset的时候,有一下语句: Map<TopicAndPartition, Object> latestOffsets ...
- Hive insert into directory 命令输出的文件没有列分隔符分析和解决
参考资料:http://stackoverflow.com/questions/16459790/hive-insert-overwrite-directory-command-output-is-n ...
- MacOS 下安装 MySQL8.0 登陆 MySQL
按照 官方教程 ,下载安装包,点击安装后,如需在命令行启动,还需设置命令路径: 在命令行中,打开配置文件 .bash_profile: vim ~/.bash_profile 在最后一行加上: PAT ...
- 全3D模具设计自动化解決方案
- key-value键值型数据库:Redis
key-value键值型数据库:Redis redis Redis是in-memory型(内存型)的键值数据库,数据在磁盘上是持久的,键类型是字符串,值类型是字符串.字符串集合(Set).sorted ...