QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#865911#1454. Um nik's Algorithmtuxuanming2024RE 5ms23552kbC++141.4kb2025-01-22 08:38:222025-01-22 08:38:23

Judging History

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

  • [2025-01-22 08:38:23]
  • 评测
  • 测评结果:RE
  • 用时:5ms
  • 内存:23552kb
  • [2025-01-22 08:38:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+5,INF=0x3f3f3f3f;
int n1,n2,m,h[N],hh[N],cnt=1,S,T,dep[N];
struct edge {int to,nxt,f,id;}e[N*4];
void Addedge(int x,int y,int f,int id=0)
{
	e[++cnt]=(edge){y,h[x],f,id},h[x]=cnt;
	e[++cnt]=(edge){x,h[y],0,id},h[y]=cnt;
}
bool bfs()
{
	memset(dep,0,sizeof(dep));
	queue<int>q; dep[S]=1,q.push(S);
	while(!q.empty())
	{
		int x=q.front(); q.pop();
		for(int i=h[x];i;i=e[i].nxt) if(e[i].f)
		{
			int y=e[i].to;
			if(!dep[y]) dep[y]=dep[x]+1,q.push(y);
		}
	}
	return dep[T];
}
int dfs(int x,int f)
{
	if(x==T||!f) return f;
	int res=0;
	for(int &i=hh[x];i;i=e[i].nxt)
	{
		int y=e[i].to;
		if(dep[x]+1==dep[y])
		{
			int d=dfs(y,min(e[i].f,f-res));
			if(d) e[i].f-=d,e[i^1].f+=d,res+=d;
			if(res==f) return res;
		}
	}
	return res;
}
int main()
{
#ifdef LOCAL
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
	freopen("1.err","w",stderr);
#endif
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n1>>n2>>m,S=n1+n2+1,T=S+1;
	for(int i=1,x,y;i<=m;i++) cin>>x>>y,Addedge(x,y+n1,1,i);
	for(int i=1;i<=n1;i++) Addedge(S,i,1);
	for(int i=1;i<=n2;i++) Addedge(i+n1,T,1);
	int t=20,res=0;
	while(t--&&bfs()) memcpy(hh,h,sizeof(h)),res+=dfs(S,INF);
	cout<<res<<"\n";
	vector<int>ans;
	for(int x=1;x<=n1;x++)
		for(int i=h[x];i;i=e[i].nxt) if(e[i].id&&!e[i].f) ans.emplace_back(e[i].id);
	for(auto x:ans) cout<<x<<"\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 20456kb

input:

3 2 4
1 1
2 1
3 1
3 2

output:

2
2
4

result:

ok answer: 2, maximum: 2

Test #2:

score: 0
Accepted
time: 0ms
memory: 19556kb

input:

20 20 20
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
18 18
19 19
20 20

output:

20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

result:

ok answer: 20, maximum: 20

Test #3:

score: 0
Accepted
time: 5ms
memory: 21360kb

input:

1000 1000 10000
988 405
844 805
40 354
416 591
520 704
697 24
315 386
122 390
991 213
506 14
309 298
26 829
329 63
787 91
971 703
805 699
624 645
121 181
841 741
473 84
258 116
490 753
725 603
265 302
869 71
611 507
59 292
11 532
117 61
192 600
650 342
204 580
687 675
670 407
637 622
569 236
728 476...

output:

1000
7650
8240
3037
2330
9523
1971
4134
3228
4607
233
7021
5673
1590
5174
2099
2942
9530
5621
6246
8427
3728
9353
4094
9557
7483
7052
9871
972
8608
9227
5936
2718
5572
7128
697
7073
5993
8419
1703
3
3722
2137
993
4682
2727
7898
4164
297
5103
9193
6897
2398
1759
8374
401
603
9714
7175
8210
4466
234
1...

result:

ok answer: 1000, maximum: 1000

Test #4:

score: 0
Accepted
time: 0ms
memory: 19820kb

input:

100 2 200
40 1
22 2
75 2
79 1
27 2
11 1
7 1
64 1
21 1
57 2
47 1
4 2
61 2
37 1
8 2
32 2
84 1
63 1
67 1
86 2
88 2
73 1
17 1
94 2
44 2
19 2
16 1
33 2
92 1
24 2
100 2
18 2
85 1
7 2
43 1
82 2
15 2
88 1
91 1
65 1
69 1
36 1
6 2
23 2
58 1
59 1
64 2
38 1
72 1
99 1
76 1
11 2
2 2
98 1
66 2
77 1
47 2
98 2
52 2
...

output:

2
150
116

result:

ok answer: 2, maximum: 2

Test #5:

score: 0
Accepted
time: 4ms
memory: 19664kb

input:

1000 1000 1000
411 789
753 186
495 203
417 324
490 424
195 480
314 23
663 218
12 747
124 390
134 38
218 536
291 840
174 908
474 767
313 167
575 9
857 427
313 27
959 935
258 70
472 957
747 228
205 939
293 303
626 802
712 283
658 346
208 383
889 204
99 640
801 966
828 742
534 11
259 734
226 129
843 35...

output:

540
384
154
274
96
490
97
806
995
694
464
848
443
199
610
738
669
342
597
701
393
774
42
269
446
408
122
685
959
842
628
771
624
474
258
965
841
555
374
49
307
846
212
847
898
31
66
911
50
113
861
952
683
787
930
884
950
729
905
837
486
796
473
778
52
571
558
570
629
11
103
364
714
805
206
676
210
7...

result:

ok answer: 540, maximum: 540

Test #6:

score: 0
Accepted
time: 4ms
memory: 23552kb

input:

1000 2000 3000
143 619
571 526
215 1074
6 1714
370 937
120 784
134 1671
722 1528
397 345
464 401
198 589
283 564
212 232
527 286
237 1649
413 1570
964 1731
194 645
639 735
182 656
641 1143
535 98
113 596
787 972
306 818
657 1202
321 1327
753 1088
122 1823
471 611
516 811
380 1548
872 973
509 1841
70...

output:

944
2279
2715
2066
2529
2481
820
620
770
1743
2377
1541
2663
1639
1826
1804
2485
2461
2866
2567
2274
91
2886
2421
2561
2639
1595
2248
1883
1677
2761
2067
2954
773
2539
2458
2762
1614
2259
2368
2677
1322
1933
1147
1907
1836
2158
2724
2623
1345
2392
2114
2739
1898
2776
2829
490
2098
1395
187
638
1728
...

result:

ok answer: 944, maximum: 944

Test #7:

score: -100
Runtime Error

input:

2000000 2000000 2000000
1203137 1030076
215220 238101
293102 491863
1260446 165178
1683989 1718181
1641329 1179380
708733 403707
1918936 574923
525651 11571
1169951 422281
1086376 303530
1286459 1692862
31854 394688
916288 273853
709758 1176923
1730408 1766172
1890708 588004
344339 283448
1676753 13...

output:


result: