最短路,三进制状态压缩。

$dis[i][j]$表示到$i$节点,每个中介用了几次的情况下的最小花费,跑最短路即可。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<iostream>
using namespace std; int n,m,q;
int e[],f[],r[]; struct X
{
int a,b,z,d;
int nx;
}ee[]; struct Y
{
int id,st,dis;
Y(int ID,int ST,int DIS)
{
id=ID;
st=ST;
dis=DIS;
} bool operator <(const Y&y) const
{
return dis>y.dis;
}
}; int h[], dis[][];
int t[]; void dij()
{
for(int i=;i<n;i++)
for(int j=;j<t[m];j++)
dis[i][j]=0x7FFFFFFF; dis[][]=;
priority_queue<Y>Q; Q.push(Y(,,)); while(!Q.empty())
{
Y q = Q.top(); Q.pop();
if(q.dis>dis[q.id][q.st]) continue;
if(q.id==n-)
{
printf("%d\n",q.dis);
return ;
} for(int i=h[q.id];i!=-;i=ee[i].nx)
{
int tmp=q.st;
for(int j=;j<m;j++) r[j]=tmp%,tmp/=; int cost = ee[i].d, v = ;
if(r[ee[i].z]==) cost += e[ee[i].z];
else if(r[ee[i].z]==) cost += f[ee[i].z],v=; if(q.dis+cost<dis[ee[i].b][q.st+v*t[ee[i].z]])
{
dis[ee[i].b][q.st+v*t[ee[i].z]] = q.dis+cost;
Q.push(Y(ee[i].b,q.st+v*t[ee[i].z],dis[ee[i].b][q.st+v*t[ee[i].z]]));
}
}
}
} int main()
{
t[]=; for(int i=;i<=;i++) t[i]=*t[i-]; while(~scanf("%d%d%d",&n,&m,&q))
{
for(int i=;i<m;i++) scanf("%d",&e[i]);
for(int i=;i<m;i++) scanf("%d",&f[i]); memset(h,-,sizeof h); for(int i=;i<=q;i++)
{
scanf("%d%d%d%d",&ee[i].a,&ee[i].b,&ee[i].z,&ee[i].d);
ee[i].nx = h[ee[i].a];
h[ee[i].a]=i;
} dij();
}
return ;
}

NBUT 1221 Intermediary的更多相关文章

  1. NBUT 1221 Intermediary 2010辽宁省赛

    Time limit 1000 ms Memory limit 131072 kB It is widely known that any two strangers can get to know ...

  2. NBUT 1457 莫队算法 离散化

    Sona Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Submit Status Practice NBUT 145 ...

  3. BZOJ 1221: [HNOI2001] 软件开发

    1221: [HNOI2001] 软件开发 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1428  Solved: 791[Submit][Stat ...

  4. ACM: NBUT 1107 盒子游戏 - 简单博弈

     NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  5. ACM: NBUT 1105 多连块拼图 - 水题 - 模拟

    NBUT 1105  多连块拼图 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  6. ACM: NBUT 1646 Internet of Lights and Switches - 二进制+map+vector

    NBUT 1646 Internet of Lights and Switches Time Limit:5000MS     Memory Limit:65535KB     64bit IO Fo ...

  7. ural 1221. Malevich Strikes Back!

    1221. Malevich Strikes Back! Time limit: 1.0 secondMemory limit: 64 MB After the greatest success of ...

  8. 【BZOJ】1221: [HNOI2001] 软件开发(最小费用最大流)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1221 先吐槽一下,数组依旧开小了RE:在spfa中用了memset和<queue>的版本 ...

  9. NBUT 1525 Cow Xor(01字典树+前缀思想)

    [1525] Cow Xor 时间限制: 2000 ms 内存限制: 65535 K 问题描述 农民约翰在喂奶牛的时候被另一个问题卡住了.他的所有N(1 <= N <= 100,000)个 ...

随机推荐

  1. Global Vectors forWord Representation

    参考论文: GloVe: Global Vectors forWord Representation 参考博客:https://blog.csdn.net/coderTC/article/detail ...

  2. 贪心+离散化+线段树上二分。。。 Samara University ACM ICPC 2016-2017 Quarterfinal Qualification Contest G. Of Zorcs and Axes

    题目链接:http://codeforces.com/gym/101149/problem/G 题目大意:给你n对数字,为(a[i], b[i]),给你m对数字,为(w[i], c[i]).给n对数字 ...

  3. DLL初试

    环境: VC++6.0 步骤: 1.建立一个WIN32 DYNAMIC-LINK LIBRARY工程,编写CPP文件,文件内容例如: #include "stdafx.h" #in ...

  4. What are the advantages of different classification algorithms?

    What are the advantages of different classification algorithms? For instance, if we have large train ...

  5. ② 设计模式的艺术-02.简单工厂(Simple Factory)模式

    工厂模式 实现了创建者和调用者的分离. 详细分类:简单工厂模式.工厂方法模式.抽象工厂模式 面向对象设计的基本原则 OCP(开闭原则,Open-Closed Principle):一个软件的实体应当对 ...

  6. koa源码阅读[1]-koa与koa-compose

    接上次挖的坑,对koa2.x相关的源码进行分析 第一篇.不得不说,koa是一个很轻量.很优雅的http框架,尤其是在2.x以后移除了co的引入,使其代码变得更为清晰. express和koa同为一批人 ...

  7. python-num18 - django进阶一

    一.深入django的路由系统 下面为django的请求生命周期 下面来看下整个生命周期中的路由系统: 在Django的urls中我们可以根据一个URL对应一个函数名来定义路由规则如下: " ...

  8. discuz2.5登录后台闪退的解决办法

    今天突然发现discuz2.5论坛后台进不去,开始以为密码错了,但发现登录后也是闪退.我试着清除浏览器cookie,也换了其他浏览器也没有用,还是上网找找吧! discuz2.5进入后台闪退的原因: ...

  9. MacOS Safari 中 button 不能使用 text-gradient

    @mixin text-gradient ($deg: 90deg, $from: $gradientFrom, $to: $gradientEnd) { background-image: line ...

  10. mysql安装后开启远程

    操作系统为centos7 64 1.修改 /etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1 这一行配置让 mysqld 启动时不对密码进行验证 2. ...