QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#35414#1454. Um nik's AlgorithmPineAppleblue17WA 5ms26872kbC++201.5kb2022-06-15 22:35:262022-06-15 22:35:27

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-15 22:35:27]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:26872kb
  • [2022-06-15 22:35:26]
  • 提交

answer

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int N=4e6+5,M=6e6+5,INF=1e9;
int n,m,s,t,c,ans,dis[N],cur[N],q[M*10];
struct nod{
	int to,nxt,w;
}e[M*2];
int head[N],cnt=1;

inline int rd(){
	int tot=0;
	char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) tot=(tot<<1)+(tot<<3)+(c^'0'),c=getchar();
	return tot;
}

void add(int u,int v,int w){
	e[++cnt].to=v,e[cnt].w=w;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}

bool bfs(){
	memset(dis,-1,sizeof(dis));
	int h=1,tt=1;
	q[1]=s,dis[s]=1;
	while(h<=tt){
		int u=q[h];
		for(int i=head[u];i;i=e[i].nxt){
			int v=e[i].to;
			if(dis[v]==-1 && e[i].w>0) dis[v]=dis[u]+1,q[++tt]=v;
		}
		h++;
	}
	return dis[t]!=-1;
}

int dfs(int o,int flow){
	if(o==t) return flow;
	int delta=flow;
	for(int i=cur[o];i;i=e[i].nxt){
		cur[o]=i;
		int v=e[i].to;
		if(dis[v]==dis[o]+1 && e[i].w){
			int tmp=dfs(v,min(delta,e[i].w));
			e[i].w-=tmp,e[i^1].w+=tmp,delta-=tmp;
			if(!delta) break;
		}
	}
	return flow-delta;
}

int dinic(){
	int ct=0;
	while(bfs() && ct<1){
		for(int i=1;i<=t;i++) cur[i]=head[i];
		ans+=dfs(s,INF);
		ct++;
	}
	return ans;
}

int rec[M];

int main(){
	n=rd(),m=rd(),c=rd();
	s=n+m+1,t=n+m+2;
	for(int i=1;i<=n;i++) add(s,i,1),add(i,s,0);
	for(int i=n+1;i<=n+m;i++) add(i,t,1),add(t,i,0);
	
	for(int i=1;i<=c;i++){
		int u=rd(),v=rd();
		v+=n;
		add(u,v,INF),add(v,u,0);
		rec[i]=cnt;
	}
	printf("%d\n",dinic());
	for(int i=1;i<=c;i++) if(e[rec[i]].w) printf("%d\n",i);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 24628kb

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: 1ms
memory: 25344kb

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: -100
Wrong Answer
time: 3ms
memory: 26872kb

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:

930
3
153
171
173
233
234
297
401
414
515
583
603
677
697
791
853
936
972
987
993
1009
1031
1085
1197
1278
1280
1313
1337
1504
1516
1606
1690
1768
1836
1894
1971
1977
2031
2042
2053
2118
2122
2132
2137
2214
2216
2256
2304
2330
2398
2421
2489
2513
2549
2576
2639
2663
2718
2727
2735
2758
2815
2823
283...

result:

wrong answer found matching is too small: 930, maximum: 1000