比赛 |
20161116 |
评测结果 |
AATTTTTTTT |
题目名称 |
冰桥,升起来了! |
最终得分 |
20 |
用户昵称 |
dududu |
运行时间 |
8.011 s |
代码语言 |
C++ |
内存使用 |
10.62 MiB |
提交时间 |
2016-11-16 11:37:28 |
显示代码纯文本
//violent code by dudu
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int KN =1e5+10;
const int KM =6e5+10;
int A,B,N,M,G_cnt;
int data[KN];
int first[KN];
struct Graph{
int fr,to,cost,next;
Graph(){fr=to=cost=next=0;};
Graph(int fr_,int to_,int cost_,int next_){
fr=fr_,to=to_,cost=cost_,next=next_;
}
Graph operator =(const Graph tmp){
fr=tmp.fr,to=tmp.to,cost=tmp.cost,next=tmp.next;
return *this;
}
}G[KM];
int d[KN];
void init(){
scanf("%d %d %d",&A,&B,&M);
N=A+B;
for(int i=1;i<=N;i++) scanf("%d",&data[i]);
int fr,to;
for(int i=1;i<=M;i++){
scanf("%d %d",&fr,&to);
G[++G_cnt]=Graph(fr,A+to,data[A+to],first[fr]);first[fr]=G_cnt;
G[++G_cnt]=Graph(A+to,fr,data[fr],first[A+to]);first[A+to]=G_cnt;
}
for(int i=1;i<=N;i++){
G[++G_cnt]=Graph(0,i,data[i],first[0]);first[0]=G_cnt;
G[++G_cnt]=Graph(i,N+1,0,first[i]);first[i]=G_cnt;
}
}
struct Status{
int v,now,last;
Status(){v=now=last=0;}
Status(int v_,int now_,int last_){
v=v_,now=now_,last=last_;
}
};
struct my_cmp{
bool operator ()(const Status a,const Status b){
return a.v<b.v;
}
};
void dij(){
memset(d,0,sizeof d);
priority_queue<Status,vector<Status>,my_cmp> q;
q.push(Status(0,0,0));
while(!q.empty()){
int nowv=q.top().v,now=q.top().now,last=q.top().last;
q.pop();
for(int i=first[now];i;i=G[i].next){
int to=G[i].to,cost=G[i].cost;
if(to<=last) continue;
d[to]=max(d[to],nowv+cost);
q.push(Status(nowv+cost,to,now));
}
}
printf("%d",d[N+1]);
}
int main(){
// freopen("test.in","r",stdin);
freopen("meibridge.in","r",stdin);
freopen("meibridge.out","w",stdout);
init();
dij();
return 0;
}