比赛 |
20160415 |
评测结果 |
WWWTTTTTTT |
题目名称 |
能量网络 |
最终得分 |
0 |
用户昵称 |
咸鱼二号 |
运行时间 |
7.005 s |
代码语言 |
C++ |
内存使用 |
1.10 MiB |
提交时间 |
2016-04-15 10:47:14 |
显示代码纯文本
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #include<string>
- #include<algorithm>
- #include<cmath>
- #include<utility>
- #include<cstdlib>
- #include<iomanip> //cout<<setiosflags(ios::fixed)<<setprecision(2);
- #include<ctime> //double a=(double)clock(); cout<<a<<endl;
- #include<vector>
- #include<queue>
- using namespace std;
- const int INF=(1LL<<31)-1;
- const int maxn=1010;
- inline int read(){
- int x=0,ff=1;char ch=getchar();
- while(ch>'9'||ch<'0'){if(ch=='-')ff=-1; ch=getchar();}
- while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
- return ff*x;
- }
- int N,M,a[maxn],b[maxn],t1,t2;
- int now[maxn],maxx[maxn];
- int lin[maxn],len=0,Lin[maxn],Len;
- struct edge{
- int y,next;
- }e[50010],E[50010];
- inline void insert(int xx,int yy){
- e[++len].next=lin[xx];
- lin[xx]=len;
- e[len].y=yy;
- }
- inline void Insert(int xx,int yy){
- E[++Len].next=Lin[xx];
- Lin[xx]=Len;
- E[Len].y=yy;
- }
- int ans=INF;
- void dfs(int depth,int v){
- if(v>=ans)
- return;
- if(depth==N+1){
- if(v<ans)
- ans=v;
- return;
- }
- now[depth]=0;
- dfs(depth+1,v+b[depth]);
- vector<int>box;
- for(int i=Lin[depth];i;i=E[i].next){
- box.push_back(maxx[E[i].y]);
- if(a[depth]>maxx[E[i].y])
- v+=a[depth]-maxx[E[i].y],maxx[E[i].y]=a[depth];
- }
- now[depth]=a[depth];
- dfs(depth+1,v);
- for(int i=Lin[depth],j=0;i;i=E[i].next,j++)
- maxx[E[i].y]=box[j];
- }
- int main(){
- freopen("energynet.in","r",stdin);
- freopen("energynet.out","w",stdout);
- N=read(),M=read();
- for(int i=1;i<=N;i++)
- a[i]=read();
- for(int i=1;i<=N;i++)
- b[i]=read();
- for(int i=1;i<=M;i++){
- t1=read(),t2=read();
- insert(t1,t2);Insert(t2,t1);
- }
- dfs(1,0);
- printf("%d\n",ans);
- return 0;
- }