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 ...
随机推荐
- bzoj 1611: [Usaco2008 Feb]Meteor Shower流星雨【BFS】
t记录每个格子最早被砸的时间,bfs(x,y,t)表示当前状态为(x,y)格子,时间为t.因为bfs,所以先搜到的t一定小于后搜到的,所以一个格子搜一次就行 #include<iostream& ...
- printf的整型
参 数 说 明 %d 输出数字长为变量数值的实际长度 %md 输出m位(不足补空格,大于m位时按实际长度输出) %-md m含义同上.左对齐输出 %ld l(小写字母)表示输出“长整型”数据 %m1 ...
- NPOI 导出excel数据超65535自动分表
工作上遇到的问题,网上找了一些资料 整理了一个比较可行的解决方案. NPOI 大数据量分多个sheet导出 代码段 /// <summary> /// DataTable转换成Excel文 ...
- [ USACO 2017 FEB ] Why Did the Cow Cross the Road III (Gold)
\(\\\) \(Description\) 给定长度为\(2N\)的序列,\(1\text ~N\)各出现过\(2\)次,\(i\)第一次出现位置记为\(a_i\),第二次记为\(b_i\),求满足 ...
- CF848A From Y to Y
思路1: 每次贪心地选择满足i * (i - 1) / 2 <= k最大的i并从k中减去i * (i - 1) / 2,直至k为0.由于函数x * (x - 1) / 2的增长速度比2x要慢,所 ...
- Spark学习之数据读取与保存(4)
Spark学习之数据读取与保存(4) 1. 文件格式 Spark对很多种文件格式的读取和保存方式都很简单. 如文本文件的非结构化的文件,如JSON的半结构化文件,如SequenceFile结构化文件. ...
- 如何利用sql注入进行爆库
SQL注入能做什么 在<SQL注入基础>一文介绍了SQL注入的基本原理和实验方法,那接下来就要问一下,SQL注入到底能什么? 估计很多朋友会这样认为:利用SQL注入最多只能获取当前表中的所 ...
- C语言入门100题,考算法的居多
入门题,考算法的居多,共同学习! 1. 编程,统计在所输入的50个实数中有多少个正数.多少个负数.多少个零. 2. 编程,计算并输出方程X2+Y2=1989的所有整数解. 3. 编程,输入一个10进制 ...
- TI 77GHZ雷达开发套件 RDP-DC100
RDP-DC100用户使用手册 目录 1. 硬件说明... 3 1.1. 官方处理板的修 ...
- Oracl常用e函数整理
最近学Oracle数据库,常常遇到Oracle数据库函数问题,经过默默地琢磨处理,总结了一些Oracle数据库常用函数. ------------------------------------ -- ...