QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#24773#3249. 分组作业suimuAC ✓43ms6960kbC++202.8kb2022-04-02 23:07:262022-04-30 06:35:39

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 06:35:39]
  • 评测
  • 测评结果:AC
  • 用时:43ms
  • 内存:6960kb
  • [2022-04-02 23:07:26]
  • 提交

answer

#include<bits/stdc++.h>
//#pragma gcc optimize(3)
#define gc getchar()
//char buf[100000],*buff = buf + 100000;
//#define gc ((buff == buf + 100000 ? (fread(buf,1,100000,stdin),buff = buf) : 0),*(buff++))
#define pc putchar
//char bfu[10000000],*bfuu = bfu;
//#define pc(x) (*(bfuu++) = x)
#define li long long
#define uli unsigned li
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define md int mid = l + r >> 1
#define ls q << 1
#define rs q << 1 | 1
#define ln ls,l,mid
#define rn rs,mid + 1,r
using namespace std;
//const int mo = 998244353;
//const int mo = 1000000007;
inline li read(){
	li x = 0;
	int y = 0,c = gc;
	while(c < '0' || c > '9') y = c,c = gc;
	while(c >= '0' && c <= '9') x = x * 10 + c - '0',c = gc;
	return y == '-' ? -x : x;
}
inline void prt(li x){
	if(x >= 10) prt(x / 10);
	pc(x % 10 + '0');
}
inline void print(li x){
	if(x < 0) pc('-'),x = -x;
	prt(x);
}
inline void file(char *s){
	char c[50];
	sprintf(c,"%s.in",s);
	freopen(c,"r",stdin);
	sprintf(c,"%s.out",s);
	freopen(c,"w",stdout);
}
li s1 = 19260817,s2 = 23333333,s3 = 998244853,srd;
inline li rd(){
	return srd = (srd * s1 + s2 + rand()) % s3;
}
struct edge{
	int to,nxt;
	li val;
}e[1000010];
int cnt = 1,fir[15010],dq[15010],n,m;
inline void ins(int u,int v,li w){
	e[++cnt].to = v;e[cnt].nxt = fir[u];fir[u] = cnt;e[cnt].val = w;
	e[++cnt].to = u;e[cnt].nxt = fir[v];fir[v] = cnt;e[cnt].val = 0;
}
int s,g,q[15010],h,t,vis[15010];
bool bfs(){
	memset(vis,0,sizeof(vis));
	vis[s] = 1;
	h = t = 0;
	q[++t] = s; 
	while(h < t){
		int x = q[++h];
		for(int i = fir[x];i;i = e[i].nxt) if(e[i].val > 0 && !vis[e[i].to]){
			vis[e[i].to] = vis[x] + 1;
			q[++t] = e[i].to;
		}
	}
	return vis[g];
}
li dfs(int q,li fl){
	if(q == g) return fl;
	li ans = 0,tmp;
	for(int &i = dq[q];i;i = e[i].nxt) if(e[i].val > 0 && vis[e[i].to] == vis[q] + 1){
		tmp = dfs(e[i].to,min(e[i].val,fl));
		ans += tmp;fl -= tmp;
		e[i].val -= tmp;e[i ^ 1].val += tmp;
		if(!fl) return ans;
	}
	if(fl) vis[q] = -1;
	return ans;
}
li wk(){
	li ans = 0,tmp;
	while(bfs()){
		memcpy(dq,fir,sizeof(dq));
		while(tmp = dfs(s,5e18l)) ans += tmp;
	}
	return ans;
}
#define team(x) (n + n + ((x) + 1 >> 1))
#define ptn(x) (((x) + 1 ^ 1) - 1)
int main(){
	srand(time(0));
	//file("");
	int i,j,a,b,c,u,v;
	n = read();m = read();
	s = n * 3 + 1;g = n * 3 + 2;
	for(i = 1;i <= n + n;++i){
		a = read();b = read();c = read();
		ins(s,team(i),a + 1e14l);
		ins(team(i),i,a + 1e14l);
		ins(i,g,b + 1e14l);
		ins(ptn(i),i,c);
	}
	for(i = 1;i <= m;++i){
		u = read();v = read();a = read();b = read();
		ins(team(u),v,a);
		ins(u,team(v),b);
	}
	print(wk() - 2e14l * n);pc('\n');
	//fwrite(bfu,1,bfuu - bfu,stdout);
	//cerr<<clock();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 38ms
memory: 5680kb

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:

22929674417

result:

ok single line: '22929674417'

Test #2:

score: 0
Accepted
time: 33ms
memory: 6044kb

input:

5000 10000
10055 16 122
4784525 16 23548777
75 3 412576
26487664 16119952 1092
3168 28 16059
33 4 13
2 1319671 7150391
17548 31559813 3201
6910 499901569 2
86633 8794940 2
4 2 85
1749 9908314 45526
10 631569 2347
18 141185 145333
23 27 117121
3825480 32645 5236
3 32022 1298
8 51750221 233
4 16102047...

output:

21306827991

result:

ok single line: '21306827991'

Test #3:

score: 0
Accepted
time: 38ms
memory: 6960kb

input:

5000 10000
48362 83079 12461784
16 4689773 2
763 3650 1128
2118 75447925 253189
47745409 622140 70841
302 162849091 1258
3399198 91 808632
16168406 10380 2
370511 10 3193109
261594 4 2
128 106331221 2
605 28343 601
19 1224480 37551173
49 78375152 493909
110536 1 836
28790 8 133
8 40 4
533035 879 391...

output:

22066314160

result:

ok single line: '22066314160'

Test #4:

score: 0
Accepted
time: 38ms
memory: 6444kb

input:

5000 10000
5564 607330 2584640
126520704 169669 3
231555 402303 114
2 128 58
290016 13 74249
8126414 279 974
1304 119651095 35466664
992290 3414 63
23564 1091 18168
418 125135735 3
29 1295683 424396930
1993 12647005 20
7 712237 1086773
500004515 6 355786
383393 486213 73
21141 29726 665
1 59959 2020...

output:

22438919820

result:

ok single line: '22438919820'

Test #5:

score: 0
Accepted
time: 43ms
memory: 6716kb

input:

5000 10000
23 1 217
41 249931 61567
3096055 3 7
24 12529 1
246322439 144141318 223606
39 906 2
22654307 3963932 3447414
7949665 51935780 344666
30 5058423 2825
148134 7532713 1140
242 5560395 4264
62940 8262918 182
7825 9865191 2992
138038614 24828018 33318812
11 1 4741355
241 533 3
4337359 741573 3...

output:

21645286114

result:

ok single line: '21645286114'

Test #6:

score: 0
Accepted
time: 40ms
memory: 6200kb

input:

5000 10000
53751618 18 124436
857 472 16
13506752 72 6929805
1313173 1 8
13 3 9428917
114702 15875684 375277
95772377 1 19
46 146 544774
2606 90182736 313
2 26253 330
92 17290550 229451029
53 3175 2
48316557 38441802 31
52027 40844521 966
2 455 40909310
6556 6662246 17592087
4914675 39 11812
4590536...

output:

24730200863

result:

ok single line: '24730200863'

Test #7:

score: 0
Accepted
time: 34ms
memory: 5928kb

input:

5000 10000
529152667 2028658 288974
46 2 1853274
212853 4442959 1
7439830 113977860 15476191
87430 6 972573
112375 4489 485
1273959 4049 4059
21 39694709 5
15511 256587916 2
164834468 4 95557537
9330 3 31231
1880144 197069 5753237
102274889 2187511 108044
1906 76869460 12
30311 27016904 6492296
1645...

output:

21376330041

result:

ok single line: '21376330041'

Test #8:

score: 0
Accepted
time: 1ms
memory: 5636kb

input:

3 2
1 1 999
1 1 999
1 999 999
1 999 999
999 1 999
999 1 999
5 1 999 1
1 3 100 1

output:

106

result:

ok single line: '106'