QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#340771#143. 最大流(随机数据)ffffyc#100 ✓11ms5784kbC++142.0kb2024-02-29 11:52:012024-02-29 11:52:02

Judging History

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

  • [2024-02-29 11:52:02]
  • 评测
  • 测评结果:100
  • 用时:11ms
  • 内存:5784kb
  • [2024-02-29 11:52:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace IO{//by cyffff
	int len=0;
	char ibuf[(1<<21)+1],*iS,*iT,out[(1<<25)+1];
	#if ONLINE_JUDGE
	#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
 	#else
	#define gh() getchar()
	#endif
	#define reg register
	inline int read(){
		reg char ch=gh();
		reg int x=0;
		reg char t=0;
		while(ch<'0'||ch>'9')   t|=ch=='-',ch=gh();
		while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
		return t?-x:x;
	}
	inline void putc(char ch){
		out[len++]=ch;
	}
	template<class T>
	inline void write(T x){
		if(x<0)putc('-'),x=-x;
		if(x>9)write(x/10);
		out[len++]=x%10+48;
	}
	inline void flush(){
		fwrite(out,1,len,stdout);
		len=0;
	}
	inline char getc(){
		char ch=gh();
		while(ch<'A'||ch>'Z') ch=gh();
		return ch;
	}
}
using IO::read;
using IO::write;
using IO::flush;
using IO::getc;
using IO::putc;
const int N=100+10,M=1e4+10;
const ll INF=1e10;
int n,m,head[N],cnt=1;
struct Edge{
	int to,nxt,fl;
}a[M];
inline void Add(int u,int v,int w){
	a[++cnt]={v,head[u],w},head[u]=cnt;
}
inline void add(int u,int v,int w){
	Add(u,v,w),Add(v,u,0);
}
int thd[N],dep[N],s,t;
inline bool bfs(){
	for(int i=1;i<=n;i++)
		thd[i]=head[i],dep[i]=n+1;
	queue<int>q;
	q.push(s),dep[s]=0;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=head[x];i;i=a[i].nxt){
			int t=a[i].to;
			if(a[i].fl&&dep[t]>dep[x]+1)
				dep[t]=dep[x]+1,q.push(t);
		}
	}
	return dep[t]<=n;
}
inline ll dfs(int x,ll fl){
	if(x==t) return fl;
	ll s=0;
	for(int i=thd[x];i&&fl;i=a[i].nxt){
		thd[x]=i;
		int t=a[i].to;
		if(dep[t]==dep[x]+1&&a[i].fl){
			ll res=dfs(t,min(fl,a[i].fl+0ll));
			a[i].fl-=res,a[i^1].fl+=res,fl-=res,s+=res;
		}
	}
	return s;
}
inline ll dinic(){
	ll sum=0;
	while(bfs())
		sum+=dfs(s,INF);
	return sum;
}
int main(){
	n=read(),m=read(),s=read(),t=read();
	for(int i=1;i<=m;i++){
		int u=read(),v=read(),w=read();
		add(u,v,w);
	}
	write(dinic());
	flush();
}

详细

Test #1:

score: 12.5
Accepted
time: 1ms
memory: 3588kb

input:

52 275 1 2
11 18 1
18 48 9
10 15 1
11 19 1
10 20 1
3 14 1
8 16 1
31 32 2147483647
10 42 9
5 14 1
3 15 1
5 17 1
6 50 9
1 6 9
28 29 2147483647
18 40 9
43 42 2147483647
1 9 9
9 20 1
1 7 9
24 6 9
39 38 2147483647
4 14 1
38 37 2147483647
5 46 9
3 18 1
15 44 9
4 17 1
32 33 2147483647
28 9 9
32 9 9
26 12 9...

output:

729

result:

ok single line: '729'

Test #2:

score: 12.5
Accepted
time: 1ms
memory: 5784kb

input:

67 4489 14 1
25 63 19983
49 18 26963
9 29 23009
25 30 10286
45 6 14693
61 11 8464
12 19 29821
39 36 2365
12 7 20737
56 51 21002
9 63 14701
15 10 24386
21 36 25930
49 21 10680
56 11 25508
26 27 2101
46 4 1770
16 56 19722
23 8 28411
67 32 28897
45 62 22880
30 38 13226
37 56 18650
10 57 700
62 53 19659...

output:

1025243

result:

ok single line: '1025243'

Test #3:

score: 12.5
Accepted
time: 0ms
memory: 3488kb

input:

100 1029 1 2
39 96 19
68 19 19
16 33 1
17 25 1
74 22 19
50 23 19
46 29 19
70 24 19
27 92 19
50 25 19
6 36 1
34 80 19
72 19 19
48 13 19
11 86 19
19 86 19
100 99 2147483647
4 39 1
60 9 19
76 7 19
34 100 19
98 97 2147483647
15 25 1
14 94 19
5 40 1
4 38 1
46 34 19
90 89 2147483647
42 39 19
58 27 19
3 39...

output:

4693

result:

ok single line: '4693'

Test #4:

score: 12.5
Accepted
time: 1ms
memory: 3608kb

input:

100 500 64 68
97 1 597234350
42 59 1020828575
52 59 1341185789
46 82 534859215
84 98 1408384018
95 85 97421544
50 51 1658946459
71 91 1071433566
16 5 577259372
79 16 941940144
32 66 2144021311
42 94 132280559
100 83 2093384600
34 98 1633024304
31 69 735801701
68 13 632197336
70 25 868338831
60 91 14...

output:

4259958644

result:

ok single line: '4259958644'

Test #5:

score: 12.5
Accepted
time: 1ms
memory: 3648kb

input:

100 1500 30 87
12 52 1212854316
66 34 500229329
28 30 1905848380
45 10 1906211267
35 5 1227091997
14 10 797678626
42 39 2119948760
80 55 263028757
72 32 1402091192
2 70 114204531
53 87 1885940117
39 68 1262963681
20 100 363298998
81 19 475298425
86 17 276841422
95 43 940479356
85 55 1720319570
40 65...

output:

17139501202

result:

ok single line: '17139501202'

Test #6:

score: 12.5
Accepted
time: 1ms
memory: 3772kb

input:

100 5000 12 73
5 90 596775756
35 20 226786760
28 31 1775982092
79 17 743002845
10 19 150120683
83 96 901953035
91 62 809520329
2 61 1024423315
30 91 1374494188
93 26 751944004
82 82 727762428
1 43 502389284
84 87 1379778919
52 32 1459460146
71 15 983677176
18 3 249963037
80 32 828290820
40 99 159181...

output:

37381805875

result:

ok single line: '37381805875'

Test #7:

score: 12.5
Accepted
time: 11ms
memory: 5600kb

input:

100 5000 13 28
74 16 599476
99 76 112185
76 68 887056
13 2 181381
23 72 214611
10 15 955272
57 53 163306
81 44 721618
68 62 71172
70 44 233121
13 52 701794
77 40 298244
54 28 626039
26 63 829000
25 14 91588
97 62 980457
17 15 572847
100 75 273645
4 65 344467
17 47 299474
40 19 270752
50 68 804106
21...

output:

2193636882

result:

ok single line: '2193636882'

Test #8:

score: 12.5
Accepted
time: 3ms
memory: 3952kb

input:

100 5000 66 90
35 39 966842
3 56 577708
38 60 515530
3 73 351251
29 27 508007
56 70 185615
73 51 331650
6 32 589603
29 96 822851
9 99 335209
20 45 806531
60 10 460779
93 21 203582
77 27 391590
3 14 315530
86 41 234991
53 69 96865
97 15 203159
14 43 815111
4 24 337097
88 79 288209
64 34 806690
13 26 ...

output:

4340954172

result:

ok single line: '4340954172'