比赛 |
20161116 |
评测结果 |
AWWTWWTTTW |
题目名称 |
冰桥,升起来了! |
最终得分 |
10 |
用户昵称 |
iortheir |
运行时间 |
4.035 s |
代码语言 |
C++ |
内存使用 |
1.52 MiB |
提交时间 |
2016-11-16 11:48:16 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
const int maxn = 40000 + 100;
int a;
int b;
int k;
int C[maxn];
int B[maxn];
struct T
{
int next;
int to;
int w;
}A[maxn];
int kount = 0;
int head[maxn];
int vis[maxn];//点
int vis1[maxn];//bian
int dis[maxn];
queue<int >q;
int ans = 0;
int u;
int v;
int W;
inline void adde(int a,int b,int w)
{
A[++ kount].next = head[a];
A[kount].to = b;
A[kount].w = w;
head[a] = kount;
}
inline void bfs(int x)
{
q.push(x);
vis[x] = 1;
dis[x] = 0;
while(!q.empty())
{
int t = q.front();
q.pop();
vis[t] = 0;
vis1[A[t].next] = 1;
for(int i = head[t];i;i = A[i].next)
{
int u = A[i].to;
/*
if(dis[u] < dis[t] + A[i].w)
{
dis[u] = dis[t] + A[i].w;
if(!vis[u])
{
q.push(u);
vis[u] = 1;
}
}
*/
if(!vis1[A[u].next])
{
if(dis[u] < dis[t] + A[i].w)
{
dis[u] = dis[t] + A[i].w;
if(!vis[u])
{
q.push(u);
vis[u] = 1;
}
}
}
}
}
}
int main()
{
freopen("meibridge.in","r",stdin);
freopen("meibridge.out","w",stdout);
scanf("%d%d%d",&a,&b,&k);
for(int i = 1;i <= a ;i ++)
{
scanf("%d",&C[i]);
}
for(int i = 1;i <= b ;i ++)
{
scanf("%d",&B[i]);
}
for(int i = 0;i < k ;i ++)
{
scanf("%d%d",&u,&v);
W = C[u] + B[v];
adde(u,v,W);
adde(v,u,W);
}
bfs(1);
for(int i = 1;i <= (a + b) / 2 ;i ++)
{
ans = max(ans,dis[i]);
}
cout<<ans + a + b;
return 0;
}