In Action

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3869    Accepted Submission(s): 1237

Problem Description

Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the number of nuclear weapons have soared across the globe.
Nowadays,the crazy boy in FZU named AekdyCoin possesses some nuclear weapons and wanna destroy our world. Fortunately, our mysterious spy-net has gotten his plan. Now, we need to stop it.
But the arduous task is obviously not easy. First of all, we know that the operating system of the nuclear weapon consists of some connected electric stations, which forms a huge and complex electric network. Every electric station has its power value. To start the nuclear weapon, it must cost half of the electric network's power. So first of all, we need to make more than half of the power diasbled. Our tanks are ready for our action in the base(ID is 0), and we must drive them on the road. As for a electric station, we control them if and only if our tanks stop there. 1 unit distance costs 1 unit oil. And we have enough tanks to use.
Now our commander wants to know the minimal oil cost in this action.
 
Input
The first line of the input contains a single integer T, specifying the number of testcase in the file.
For each case, first line is the integer n(1<= n<= 100), m(1<= m<= 10000), specifying the number of the stations(the IDs are 1,2,3...n), and the number of the roads between the station(bi-direction).
Then m lines follow, each line is interger st(0<= st<= n), ed(0<= ed<= n), dis(0<= dis<= 100), specifying the start point, end point, and the distance between.
Then n lines follow, each line is a interger pow(1<= pow<= 100), specifying the electric station's power by ID order.
 
Output
The minimal oil cost in this action.
If not exist print "impossible"(without quotes).
 
Sample Input
2
2 3
0 2 9
2 1 3
1 0 2
1
3
2 1
2 1 3
1
3
 
Sample Output
5
impossible
 
Author
Lost@HDU
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  3338 1546 3333 3341 3335 
 
 //187MS    616K    1856 B    C++
/* 题意:
题意挺重要的。一个源点0,源点每到一个站可得到一个pow[i],求得到总pow值一半以上时最短行走距离。 最短路+01背包:
首先最短路求出源点0到每一个点的距离,然后得出n个点,每个点有一个距离花费d,和一个价值权值w,
以到所有的点最短路程和作为背包容量,距离作为花费,权值作为价值,01背包。
当dp[j]>sum_pow/2+1时的距离和j为所求。 */
#include<iostream>
#include<queue>
#include<vector>
#define N 105
#define inf 0x7ffffff
using namespace std;
typedef struct node{
int d,w;
}node;
node p[N];
int vis[N];
int d[N];
int dp[N*N];
vector<node>V[N];
int n;
int Max(int x,int y)
{
return x>y?x:y;
}
void spfa(int s)
{
for(int i=;i<=n;i++)
d[i]=inf;
d[s]=;
vis[s]=;
queue<int>Q;
Q.push(s);
while(!Q.empty()){
int u=Q.front();
Q.pop();
vis[u]=;
int m=V[u].size();
for(int i=;i<m;i++){
int v=V[u][i].d;
int w=V[u][i].w;
if(d[v]>d[u]+w){
d[v]=d[u]+w;
if(!vis[v]){
vis[v]=;
Q.push(v);
}
}
}
}
}
int main(void)
{
int t,m;
int u,v,w,pow;
scanf("%d",&t);
while(t--)
{
int sd=,sw=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) V[i].clear();
for(int i=;i<m;i++){
scanf("%d%d%d",&u,&v,&w);
node q={v,w};
V[u].push_back(q);
q.d=u;
V[v].push_back(q);
}
for(int i=;i<=n;i++){
scanf("%d",&p[i].w);
sw+=p[i].w;
}
spfa();
for(int i=;i<=n;i++){
p[i].d=d[i];
if(d[i]!=inf)
sd+=p[i].d;
}
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
for(int j=sd;j>=p[i].d;j--)
dp[j]=Max(dp[j],dp[j-p[i].d]+p[i].w);
int ans=;
for(int i=;i<=sd;i++)
if(dp[i]>=sw/+){
ans=i;break;
}
if(ans==) puts("impossible");
else printf("%d\n",ans);
}
return ;
}

最新文章

  1. [JS]笔记14之事件委托
  2. Android的学习第六章(布局二--RelativeLayout)
  3. spring设置全局异常处理器
  4. iOS实现屏幕旋转
  5. V-rep学习笔记:曲柄摇杆机构
  6. 重学STM32---(三) 中断分组和优先级
  7. 图片上传前的预览(PHP)
  8. robot framework环境搭建(转)
  9. H5移动端开发入门知识以及CSS的单位汇总与用法
  10. Autofac学习之三种生命周期:InstancePerLifetimeScope、SingleInstance、InstancePerDependency
  11. IT学习逆袭的新模式,全栈实习生,不8000就业不还实习费
  12. PMP:8.项目质量管理
  13. MyBatis的Mapper接口以及Example的实例函数及详解
  14. Ubuntu 12.04图形界面不能登录问题
  15. Python的单向链表实现
  16. 使用jQuery实现返回顶部功能
  17. windows下PyCharm安装及使用
  18. windows命令:control命令
  19. 浅谈Javascript设计模式
  20. c# 解析MP3文件

热门文章

  1. Installing python-ldap in Ubuntu
  2. Luogu2917_ [USACO08NOV]奶牛混合起来Mixed Up Cows_KEY
  3. AT+CGDCONT=0,&quot;IP&quot;,&quot;ctnb&quot;设置问题
  4. steam账号分享工具、迅游账号分享工具说明:
  5. tensorflow学习一
  6. iOS UIWebView加载时添加进度条01
  7. 180612-Spring之Yml配置文件加载问题
  8. Django模型与创建管理员用户
  9. Python基础 之 文件操作
  10. Python基础框架和工具