QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#91198#3249. 分组作业INFiNiTE_ENERZYTL 0ms0kbC++141.8kb2023-03-27 17:20:562023-03-27 17:20:58

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-27 17:20:58]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-03-27 17:20:56]
  • 提交

answer

//P8215
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;
const long long inf = 1e17;
int n, m, hd[N], eg[N], nx[N], tot = 1;
int dep[N], now[N];
long long ln[N];

void add(int x, int y, long long z){
	eg[++tot] = y;
	ln[tot] = z;
	nx[tot] = hd[x];
	hd[x] = tot;
	eg[++tot] = x;
	ln[tot] = 0;
	nx[tot] = hd[y];
	hd[y] = tot;
}
bool bfs(int s, int t){
	memset(dep, 0, sizeof(dep));
	memcpy(now, hd, sizeof(hd));
	queue<int> q;
	q.push(s);
	dep[s] = 1;
	while(!q.empty()){
		int x = q.front();
		q.pop();
		for(int i = hd[x]; i; i = nx[i]){
			int y = eg[i];
			long long z = ln[i];
			if(!dep[y] && z > 0){
				dep[y] = dep[x] + 1;
				q.push(y);
				if(y == t){
					return true;
				}
			}
		}
	}
	return false;
}
long long dfs(int x, int t, long long flow){
	if(x == t){
		return flow;
	}
	long long rest = flow;
	for(int i = now[x]; i; i = nx[i]){
		int y = eg[i];
		long long z = ln[i];
		now[x] = i;
		if(z > 0 && dep[y] == dep[x] + 1){
			long long k = dfs(y, t, min(z, rest));
			if(!k){
				dep[y] = 0;
			}
			ln[i] -= k;
			ln[i^1] += k;
			rest -= k;
		}
	}
	return flow - rest;
}
long long dinic(int s, int t){
	long long mf = 0, tmp = 0;
	while(bfs(s, t)){
		while(tmp = dfs(s, t, inf)){
			mf += tmp;
		}
	}
	return mf;
}

int main(){
	scanf("%d%d", &n, &m);
	int s = 3 * n + 1, t = 3 * n + 2;
	#define p(x) (n+n+ceil((x)/2.0))
	for(int i = 1; i <= n + n; ++ i){
		int c, d, e;
		scanf("%d%d%d", &c, &d, &e);
		add(s, i, d);
		add(i, t, c);
		add(p(i), i, inf);
		if(i & 1){
			add(i, i+1, e);
		} else {
			add(i, i-1, e);
		}
	}
	for(int i = 1; i <= m; ++ i){
		int A, B, a, b;
		scanf("%d%d%d%d", &A, &B, &a, &b);
		add(B, p(A), a);
		add(A, p(B), b);
	}
	printf("%lld\n", dinic(s, t));
	return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

5000 10000
23060775 12 2
255978380 28 517
5 6624 26
151149 45131806 23849036
489 484971 24970
162846 1993316 188305
56311199 2003 211
1 50534913 517527
364913 882765 298
71 26 122914059
13 65459 18150033
20 607 8
380059068 3873712 228
9813 5449 6370
3309369 37410691 8
181 1 62340851
1705 4 107
8 209...

output:


result: