QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#72038#4128. 费用流Cyh29hao100 ✓9ms3996kbC++141.7kb2023-01-13 18:42:482023-01-13 18:42:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-13 18:42:48]
  • 评测
  • 测评结果:100
  • 用时:9ms
  • 内存:3996kb
  • [2023-01-13 18:42:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int mx=1e4+5,INF=2147483647,T=0;
const double eps=1e-5;
int n,m,s,t,u,v,w,p;
int head[mx],nxt[mx],to[mx],cnt=1,cur[mx];
double ANS=0,now[mx],dist[mx],_dist[mx];

inline void add_edge(int u,int v,int w){
	to[++cnt]=v;dist[cnt]=w;nxt[cnt]=head[u];head[u]=cnt;
	to[++cnt]=u;dist[cnt]=0;nxt[cnt]=head[v];head[v]=cnt;
}

int lv[mx];
queue <int> q;

inline bool bfs(){
	memset(lv,-1,sizeof lv);memcpy(cur,head,sizeof head);while(!q.empty())q.pop();
	
	lv[s]=0;q.push(s);
	
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i;i=nxt[i]){
			int v=to[i];double w=dist[i];
			if(w>0 && lv[v]==-1)
				lv[v]=lv[u]+1,q.push(v);
		}
	}
	return lv[t]!=-1;
}

inline double dfs(int u=s,double flow=INF){
	if(u==t)return flow;
	double ret=flow;
	for(int i=cur[u];i&&ret;i=nxt[i]){
		cur[u]=i;
		int v=to[i];double w=dist[i];
		if(w>0 && lv[v]==lv[u]+1){
			double c=dfs(v,min(ret,w));
			ret-=c;
			dist[i]-=c;dist[i^1]+=c;now[i]+=c;
		}
	}
	return flow-ret;
}

inline double dinic(double x){
	memcpy(_dist,dist,sizeof dist);
	for(int i=2;i<=cnt;i+=2){
		dist[i]=min(dist[i],x);
		//dist[i+1]=-dist[i];
	}
	double ans=0;
	while(bfs())ans+=dfs();
	memcpy(dist,_dist,sizeof dist);
	return ans;
}

inline bool check(double x){
	if(T)printf("    limit=%lf,ans=%lf\n",x,dinic(x));
	return dinic(x)==ANS;
}

int main()
{
	scanf("%d%d%d",&n,&m,&p);s=1;t=n;
	while(m--)scanf("%d%d%d",&u,&v,&w),add_edge(u,v,w);
	ANS=dinic(50000);
	
	double l=1,r=50000,mid=0;
	while(r-l>eps){
		mid=(l+r)/2;if(T)printf("  mid=%lf\n",mid);
		if(!check(mid))l=mid;
		else r=mid;
	}
	printf("%d\n%.4lf",(int)ANS,r*p);printf("\n");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 9ms
memory: 3936kb

input:

70 1000 1
25 26 821
26 27 467
27 28 689
28 29 131
29 30 998
30 31 299
31 32 237
32 33 692
33 34 531
34 35 938
35 36 338
36 37 986
37 38 182
38 39 533
39 40 395
40 41 117
41 42 901
42 43 232
43 44 711
44 45 539
45 46 760
46 47 497
47 48 27
48 49 916
49 50 535
50 51 771
51 52 30
52 53 405
53 54 257
54...

output:

19749
9874.5000

result:

points 1.0 First Answer Correct, Second Answer Correct (error = 0.000000000)

Test #2:

score: 10
Accepted
time: 2ms
memory: 3928kb

input:

100 1000 10
25 26 390
26 27 715
27 28 480
28 29 397
29 30 24
30 31 95
31 32 233
32 33 560
33 34 404
34 35 266
35 36 94
36 37 946
37 38 510
38 39 873
39 40 472
40 41 90
41 42 573
42 43 501
43 44 414
44 45 387
45 46 391
46 47 915
47 48 313
48 49 77
49 50 522
50 51 773
51 52 816
52 53 746
53 54 996
54 ...

output:

7105
35525.0000

result:

points 1.0 First Answer Correct, Second Answer Correct (error = 0.000000000)

Test #3:

score: 10
Accepted
time: 3ms
memory: 3928kb

input:

100 1000 10
25 26 338
26 27 692
27 28 457
28 29 540
29 30 725
30 31 715
31 32 758
32 33 534
33 34 347
34 35 302
35 36 125
36 37 4
37 38 171
38 39 910
39 40 55
40 41 954
41 42 438
42 43 186
43 44 725
44 45 512
45 46 898
46 47 436
47 48 273
48 49 469
49 50 376
50 51 509
51 52 245
52 53 104
53 54 70
54...

output:

7869
39345.0001

result:

points 1.0 First Answer Correct, Second Answer Correct (error = 0.000000003)

Test #4:

score: 10
Accepted
time: 5ms
memory: 3984kb

input:

60 1000 1
25 26 128
26 27 415
27 28 198
28 29 649
29 30 101
30 31 195
31 32 573
32 33 598
33 34 758
34 35 35
35 36 146
36 37 457
37 38 936
38 39 479
39 40 378
40 41 871
41 42 482
42 43 627
43 44 272
44 45 484
45 46 159
46 47 217
47 48 353
48 49 109
49 50 576
50 51 388
51 52 847
52 53 711
53 54 312
5...

output:

20435
10217.5000

result:

points 1.0 First Answer Correct, Second Answer Correct (error = 0.000000000)

Test #5:

score: 10
Accepted
time: 6ms
memory: 3936kb

input:

75 1000 5
25 26 1
26 27 53
27 28 300
28 29 595
29 30 413
30 31 955
31 32 754
32 33 594
33 34 641
34 35 372
35 36 548
36 37 935
37 38 437
38 39 694
39 40 804
40 41 912
41 42 576
42 43 611
43 44 115
44 45 114
45 46 912
46 47 711
47 48 841
48 49 789
49 50 564
50 51 269
51 52 278
52 53 819
53 54 987
54 ...

output:

11780
29450.0000

result:

points 1.0 First Answer Correct, Second Answer Correct (error = 0.000000000)

Test #6:

score: 10
Accepted
time: 6ms
memory: 3864kb

input:

55 600 9
21 22 844
22 23 799
23 24 352
24 25 793
25 26 625
26 27 815
27 28 43
28 29 628
29 30 701
30 31 70
31 32 537
32 33 515
33 34 541
34 35 283
35 36 137
36 37 734
37 38 522
38 39 312
39 40 583
40 41 785
41 42 434
42 43 506
43 44 313
44 45 501
45 46 374
46 47 356
47 48 507
48 49 69
49 50 386
50 5...

output:

15077
67846.5000

result:

points 1.0 First Answer Correct, Second Answer Correct (error = 0.000000000)

Test #7:

score: 10
Accepted
time: 5ms
memory: 3936kb

input:

50 1000 2
1 2 1
2 3 1
3 4 1
4 5 1
5 6 1
6 7 1
7 8 1
8 9 1
9 10 1
10 11 1
11 12 1
12 13 1
13 14 1
14 15 1
15 16 1
16 17 1
17 18 1
18 19 1
19 20 1
20 21 1
21 22 1
22 23 1
23 24 1
24 25 1
25 26 1
26 27 1
27 28 1
28 29 1
29 30 1
30 31 1
31 32 1
32 33 1
33 34 1
34 35 1
35 36 1
36 37 1
37 38 1
38 39 1
39 ...

output:

29
2.0000

result:

points 1.0 First Answer Correct, Second Answer Correct (error = 0.000000000)

Test #8:

score: 10
Accepted
time: 6ms
memory: 3996kb

input:

50 1000 3
1 2 1
2 3 1
3 4 1
4 5 1
5 6 1
6 7 1
7 8 1
8 9 1
9 10 1
10 11 1
11 12 1
12 13 1
13 14 1
14 15 1
15 16 1
16 17 1
17 18 1
18 19 1
19 20 1
20 21 1
21 22 1
22 23 1
23 24 1
24 25 1
25 26 1
26 27 1
27 28 1
28 29 1
29 30 1
30 31 1
31 32 1
32 33 1
33 34 1
34 35 1
35 36 1
36 37 1
37 38 1
38 39 1
39 ...

output:

34
3.0000

result:

points 1.0 First Answer Correct, Second Answer Correct (error = 0.000000000)

Test #9:

score: 10
Accepted
time: 4ms
memory: 3856kb

input:

50 300 8
17 18 11
18 19 385
19 20 167
20 21 155
21 22 550
22 23 789
23 24 197
24 25 689
25 26 480
26 27 585
27 28 406
28 29 79
29 30 189
30 31 578
31 32 728
32 33 660
33 34 350
34 35 987
35 36 517
36 37 612
37 38 870
38 39 846
39 40 115
40 41 318
41 42 318
42 43 911
43 44 812
44 45 269
45 46 66
46 4...

output:

4965
19860.0000

result:

points 1.0 First Answer Correct, Second Answer Correct (error = 0.000000000)

Test #10:

score: 10
Accepted
time: 6ms
memory: 3884kb

input:

80 1000 6
25 26 286
26 27 77
27 28 378
28 29 452
29 30 481
30 31 335
31 32 52
32 33 564
33 34 290
34 35 105
35 36 693
36 37 469
37 38 8
38 39 658
39 40 45
40 41 817
41 42 711
42 43 694
43 44 804
44 45 813
45 46 637
46 47 190
47 48 825
48 49 397
49 50 766
50 51 301
51 52 441
52 53 461
53 54 145
54 55...

output:

10502
31506.0000

result:

points 1.0 First Answer Correct, Second Answer Correct (error = 0.000000000)