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 ...
随机推荐
- 浙江省CIO协会钱塘江论坛近日在网易云创沙龙宣布成立
本文来自网易云社区 9月19日,由网易云与浙江省首席信息官协会共同主办的“网易云创CIO沙龙”在杭州举行,本次活动以“瞩目钱塘,赋能企业数字化创新”为主题,网易云企业服务部总经理岳峥辉,浙江省首席信息 ...
- E20170611-hm
ascending adj. 上升的,向上的; ascend vt. 攀登; 继承; 占领; vi. 上升; 爬坡; 追溯; descending n. 递减; descend v ...
- android序列化(1)Parcelable与Serializable
1.Android中实现序列化有两个选择 一是实现Serializable接口(是JavaSE本身就支持的),实现Serializable接口非常简单. 一是实现Parcelable接口(是Andro ...
- D. Fedor and coupons 二分暴力
http://codeforces.com/contest/754/problem/D 给出n条线段,选出k条,使得他们的公共部分长度最大. 公共部分的长度,可以二分出来,为val.那么怎么判断有k条 ...
- javascript 信息的发布与删除
现在很多类似以微博发布动态的效果,下面为一个用 JavaScript写的小小的类似微博发布信息的案例 <!DOCTYPE html> <html lang="en" ...
- 用Martini、websocket实现单机版聊天室
ChatRoom A stand-alone ChatRoom in Martini Please Star https://github.com/renleimlj/ChatRoom Interfa ...
- [ POI 2010 ] Antisymmetry
\(\\\) \(Description\) 给出一个长度为 \(N\) 的二进制串,定义一个子串是优秀的,当且仅当其正着看,和倒着按位取反后看结果是一样的,求整个串有多少个优秀的子串. \(N\le ...
- leetcode464 Can I Win
思路: 博弈. 实现: class Solution { public: bool dfs(int cur, int len, int sum, int des, vector<int>& ...
- 修改 进程占用资源限制ulimit(限制服务器的链接数目)
ulimit用于限制shell启动进程所占用的资源.其中ulimit -n用于限制进程能够打开的文件描述符的最大数目.因为任何设备在linux下都是文件,通信的接口也有专门的接口文件负责,所以linu ...
- phpcms标签第三弹
{CHARSET} -------------------------------------字符集 (gbk或者utf-8) {if isset($SEO['title']) && ...