比赛 |
20161116 |
评测结果 |
TATTTEEEEE |
题目名称 |
冰桥,升起来了! |
最终得分 |
10 |
用户昵称 |
BIRD |
运行时间 |
4.447 s |
代码语言 |
C++ |
内存使用 |
110.69 MiB |
提交时间 |
2016-11-16 11:59:09 |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
int A, B, K, ans = 0;
int pu[40005], pw[40005], con1[4005][4005], con2[4005][4005];
int sea(int begin,int side, int value){
for(int i = 1; i <= (side == 2?A:B);i++){
if(side ==1 && con1[begin][i]) return sea(i, 1, value + pu[i]);
if(side ==2 && con2[begin][i]) return sea(i, 2, value + pw[i]);
}
return value;
}
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", &pu[i]);
for(int i = 1; i <= B; i++)
scanf("%d", &pw[i]);
for(int i = 1; i <= K; i++) {
int bird, b1;
scanf("%d%d", &bird, &b1);
con1[bird][b1] = 1;
con2[b1][bird] = 1;
}
//保证冰桥没有重复
for(int i = 1; i <= A; i++)
ans = max(ans, sea(i, 1, pu[i]));
for(int i = 1; i <= B; i++)
ans = max(ans, sea(i, 2, pw[i]));
printf("%d", ans);
return 0;
}