比赛 20160415 评测结果 TTTWWWWWWW
题目名称 能量网络 最终得分 0
用户昵称 Fmuckss 运行时间 3.025 s
代码语言 C++ 内存使用 3.02 MiB
提交时间 2016-04-15 11:57:57
显示代码纯文本
#include<iostream>
#include<cstdio>
using namespace std;
const int maxm = 5e4+10;
const int maxn = 1e3+10;

int a[maxn], b[maxn], n, m;

class violence {
private:
	struct edge {
		int to, ne;
		edge() {}
		edge(int to_, int ne_) { to = to_, ne = ne_; }
	}e[maxn];
	int head[maxm], tot;
	
	void add_edge(int fr, int to) {
		e[++tot] = edge(to, head[fr]); head[fr] = tot;
	}
	
	int ans;
	int chan;
	bool exi[maxn];
public:
	violence() { ans = 1e9; }
	
	void read() {
		int fr, to;
		for(int i = 1; i <= m; i++) {
			scanf("%d %d", &fr, &to);
			add_edge(fr, to);
		}
	}
	
	int get_cos() {
		int tot = 0;
		for(int i = 1; i <= n; i++) {
			int now_max = 0;
			for(int j = head[i]; j; j = e[i].ne) {
				if(exi[e[i].to]) continue;
				now_max = max(now_max, a[e[i].to]);
			}
			tot += now_max;
		}
		return tot;
	}
	
	void solve(int now, int cos) {
		ans = min(ans, get_cos()+cos);
		if(now == n+1) return;
		solve(now+1, cos);
		exi[now] = true;
		solve(now+1, cos+b[now]);
	} 
	
	void out() {
		printf("%d\n", ans);
	}
}vl;

class cheat {
private:
	bool use[maxn];
public:
	void solve() {
		int ans = 0; 
		for(int i = 1; i <= m; i++) {
			int fr, to;
			scanf("%d %d", &fr, &to);
			if(use[to]) continue;
			use[to] = true;
			ans += b[to];
		}
		printf("%d", ans);
	}
}ch;


void read() {
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for(int i = 1; i <= n; i++) {
		scanf("%d", &b[i]);
	}
}

void solve() {
	if(n >= 27) {
		ch.solve();
		return;
	}
	vl.read();
	vl.solve(1, 0);
	vl.out();
}

int main() {
	freopen("energynet.in", "r", stdin);
	freopen("energynet.out", "w", stdout);
	read();
	solve();
	return 0;
}