比赛 20160415 评测结果 WWWTTTTTTT
题目名称 能量网络 最终得分 0
用户昵称 咸鱼二号 运行时间 7.005 s
代码语言 C++ 内存使用 1.10 MiB
提交时间 2016-04-15 10:47:14
显示代码纯文本
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<string>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<utility>
  8. #include<cstdlib>
  9. #include<iomanip> //cout<<setiosflags(ios::fixed)<<setprecision(2);
  10. #include<ctime> //double a=(double)clock(); cout<<a<<endl;
  11. #include<vector>
  12. #include<queue>
  13. using namespace std;
  14. const int INF=(1LL<<31)-1;
  15. const int maxn=1010;
  16. inline int read(){
  17. int x=0,ff=1;char ch=getchar();
  18. while(ch>'9'||ch<'0'){if(ch=='-')ff=-1; ch=getchar();}
  19. while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
  20. return ff*x;
  21. }
  22. int N,M,a[maxn],b[maxn],t1,t2;
  23. int now[maxn],maxx[maxn];
  24. int lin[maxn],len=0,Lin[maxn],Len;
  25. struct edge{
  26. int y,next;
  27. }e[50010],E[50010];
  28. inline void insert(int xx,int yy){
  29. e[++len].next=lin[xx];
  30. lin[xx]=len;
  31. e[len].y=yy;
  32. }
  33. inline void Insert(int xx,int yy){
  34. E[++Len].next=Lin[xx];
  35. Lin[xx]=Len;
  36. E[Len].y=yy;
  37. }
  38. int ans=INF;
  39. void dfs(int depth,int v){
  40. if(v>=ans)
  41. return;
  42. if(depth==N+1){
  43. if(v<ans)
  44. ans=v;
  45. return;
  46. }
  47. now[depth]=0;
  48. dfs(depth+1,v+b[depth]);
  49. vector<int>box;
  50. for(int i=Lin[depth];i;i=E[i].next){
  51. box.push_back(maxx[E[i].y]);
  52. if(a[depth]>maxx[E[i].y])
  53. v+=a[depth]-maxx[E[i].y],maxx[E[i].y]=a[depth];
  54. }
  55. now[depth]=a[depth];
  56. dfs(depth+1,v);
  57. for(int i=Lin[depth],j=0;i;i=E[i].next,j++)
  58. maxx[E[i].y]=box[j];
  59. }
  60. int main(){
  61. freopen("energynet.in","r",stdin);
  62. freopen("energynet.out","w",stdout);
  63. N=read(),M=read();
  64. for(int i=1;i<=N;i++)
  65. a[i]=read();
  66. for(int i=1;i<=N;i++)
  67. b[i]=read();
  68. for(int i=1;i<=M;i++){
  69. t1=read(),t2=read();
  70. insert(t1,t2);Insert(t2,t1);
  71. }
  72. dfs(1,0);
  73. printf("%d\n",ans);
  74. return 0;
  75. }