QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#799905#7898. I Just Want... One More...WilliamHuWA 32ms40648kbC++172.3kb2024-12-05 19:29:562024-12-05 19:29:56

Judging History

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

  • [2024-12-05 19:29:56]
  • 评测
  • 测评结果:WA
  • 用时:32ms
  • 内存:40648kb
  • [2024-12-05 19:29:56]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
int Read(){
	int x=0;
	char ch=getchar();bool f=0;
	while(ch<'0'||ch>'9') if(ch=='-')f=1,ch=getchar(); else if(ch==EOF)return 0; else ch=getchar();
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
int h[1000005],nxt[1000005],to[1000005],val[1000005];
int cnt=1;
int n,m,s,t;
int ls[1000005],lt[1000005];
void link(int x,int y,int z){
	nxt[++cnt]=h[x];
	h[x]=cnt;
	to[cnt]=y;
	val[cnt]=z;
	if(x==2*n+1) ls[y]=cnt;
	if(y==2*n+2) lt[x]=cnt;
	nxt[++cnt]=h[y];
	h[y]=cnt;
	to[cnt]=x;
	val[cnt]=0;
	return;
}
const int inf=0x3f3f3f3f3f3f3f3f;
int dis[1000005],now[1000005];
queue<int> q;
bool bfs(){
	bool flag=0;
	for(int i=1;i<=2*n+2;i++) dis[i]=inf;
	q.push(s);
	dis[s]=0;
	now[s]=h[s];
	while(!q.empty()){
		int x=q.front();
//		cout<<x<<endl;
		q.pop();
		for(int i=h[x];i;i=nxt[i]){
			if(dis[to[i]]==inf&&val[i]>0){
				dis[to[i]]=dis[x]+1;
				now[to[i]]=h[to[i]];
				q.push(to[i]);
				if(to[i]==t) flag=1;
			}
		}
	}
	return flag;
}
int dfs(int x,int fl){
	if(x==t) return fl;
	int ans=0;
	for(int i=now[x];i&&fl;i=nxt[i]){
		now[x]=i;
		if(val[i]>0&&dis[to[i]]==dis[x]+1){
			int k=dfs(to[i],min(fl,val[i]));
			if(k==0) dis[to[i]]=inf;
			val[i]-=k;
			val[i^1]+=k;
			fl-=k;
			ans+=k;
		}
	}
	return ans;
}
bool vis1[1000005];
void dfs2(int x){
	vis1[x]=1;
	for(int i=h[x];i;i=nxt[i]){
		int p=to[i];
		if((!val[i])||vis1[p])continue;
		dfs2(p);
	}return;
}
void dfs1(int x){
	vis1[x]=1;
	for(int i=h[x];i;i=nxt[i]){
		int p=to[i];
//		cout<<x<<' '<<p<<' '<<vis1[p]<<endl;
		if(val[i]||vis1[p])continue;
		dfs1(p);
	}return;
}
bool ans[800005];
signed main() {
	int T=Read();
	while(T--){
		n=Read(),m=Read();
		for(int i=1;i<=2*n+3;i++)h[i]=0,ans[i]=0;
		while(m--){
			int x=Read(),y=Read();
			link(x,y+n,1);
		}
		for(int i=1;i<=n;i++){
			link(2*n+1,i,1);
		}for(int i=n+1;i<=2*n;i++){
			link(i,2*n+2,1);
		}
		s=2*n+1,t=2*n+2;
		while(bfs())dfs(s,inf);
//		cout<<ans<<endl;
		int ans1=0,ans2=0;
		for(int i=1;i<=2*n+3;i++)vis1[i]=0;
		dfs2(2*n+1);
		for(int i=1;i<=n;i++)ans1+=vis1[i],vis1[i]=0;
		for(int i=n+1;i<=2*n+3;i++) vis1[i]=0;
		dfs1(2*n+2);
		for(int i=n+1;i<=2*n;i++)ans2+=vis1[i];
		printf("%lld\n",ans1*ans2);
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 20420kb

input:

3
4 3
1 2
3 2
4 3
3 3
1 3
2 2
3 1
3 2
1 2
1 2

output:

6
0
4

result:

ok 3 number(s): "6 0 4"

Test #2:

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

input:

10000
5 4
2 2
3 1
5 3
1 1
1 1
1 1
1 1
1 1
2 2
2 2
1 2
1 1
1 1
1 1
1 1
1 1
1 1
2 3
2 1
1 2
1 1
5 5
1 4
2 2
3 1
1 3
1 2
2 4
2 2
2 1
1 2
1 1
5 1
5 3
3 1
2 2
1 1
1 1
3 2
3 1
2 1
5 2
1 2
2 3
5 3
1 5
4 2
1 2
4 1
1 1
2 3
1 1
2 2
2 1
4 1
1 4
3 1
1 1
1 1
1 1
2 1
2 2
3 3
1 3
2 3
2 2
3 3
1 3
3 3
1 2
3 3
2 2
1 ...

output:

6
0
0
2
0
0
0
0
6
0
16
4
0
6
9
9
9
0
9
4
0
1
1
1
0
4
16
12
3
2
16
0
2
2
20
1
0
0
0
0
16
4
4
16
4
9
0
9
0
2
3
0
9
4
9
16
20
0
0
1
12
0
1
2
0
0
1
0
0
2
2
4
0
12
1
0
0
2
1
2
2
3
0
4
1
6
0
0
0
0
9
16
2
0
1
2
0
12
2
4
0
12
1
1
9
4
6
9
9
12
3
16
15
16
9
4
9
0
1
16
9
9
1
9
16
9
12
4
9
2
0
4
0
6
0
3
0
0
0
0...

result:

ok 10000 numbers

Test #3:

score: 0
Accepted
time: 8ms
memory: 28324kb

input:

10000
8 1
8 7
8 6
4 5
8 8
6 6
5 3
6 3
8 6
2 3
1 2
2 2
2 1
4 5
1 3
1 2
2 3
1 1
3 3
8 8
4 3
7 3
1 6
5 4
6 3
2 2
6 7
2 5
1 1
1 1
10 2
4 7
9 7
8 10
5 5
5 1
5 2
4 1
3 5
2 4
5 4
6 3
6 4
2 8
10 5
6 10
6 1
7 2
6 6
8 10
8 3
8 4
5 8
2 5
7 1
5 7
5 8
4 2
2 2
5 3
3 4
3 3
4 4
2 5
1 2
1 1
1 1
5 8
4 3
2 4
5 3
2 3
2...

output:

49
16
0
9
16
0
90
18
56
25
36
4
0
6
56
24
9
24
1
9
0
4
90
6
1
30
30
4
0
0
49
15
30
35
20
9
9
36
16
6
35
4
49
24
81
3
0
12
72
36
30
12
9
36
10
2
30
0
0
0
35
0
1
8
0
0
15
6
0
25
49
0
0
3
1
0
8
16
20
0
36
81
0
3
9
30
8
36
0
25
0
49
16
1
0
16
0
0
0
25
8
0
64
64
0
64
9
6
0
81
45
36
16
0
1
25
49
8
4
2
20
...

result:

ok 10000 numbers

Test #4:

score: 0
Accepted
time: 17ms
memory: 32444kb

input:

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

output:

80
16
20
289
130
144
42
15
169
210
2
36
99
28
144
12
56
169
0
42
36
289
100
70
0
225
81
12
42
4
225
0
12
0
12
168
100
72
289
144
210
100
18
80
110
180
210
0
35
0
64
0
0
130
144
0
40
144
20
0
20
2
121
108
120
132
12
120
42
81
182
9
196
0
0
0
9
99
0
110
132
21
96
0
0
72
8
108
132
25
196
42
221
49
1
72...

result:

ok 10000 numbers

Test #5:

score: 0
Accepted
time: 27ms
memory: 38864kb

input:

10000
17 13
2 9
7 12
1 10
9 15
16 9
10 11
10 4
6 4
10 15
16 13
15 11
11 11
1 12
9 19
9 1
7 2
4 2
4 8
3 9
1 2
3 2
2 8
4 4
3 7
1 7
3 1
9 2
3 4
8 3
2 5
2 3
9 7
8 5
23 25
15 14
14 9
20 17
7 15
20 5
9 22
19 4
1 3
5 18
22 23
17 7
19 5
4 11
22 20
11 4
8 21
7 17
2 12
6 6
11 3
3 14
11 14
3 20
15 5
6 5
27 15
...

output:

130
12
49
272
4
0
342
306
462
8
42
16
143
9
40
0
156
16
234
30
9
126
238
36
0
36
110
441
165
18
30
306
91
121
0
3
225
110
0
48
399
169
0
154
56
8
4
0
18
16
324
117
0
1
9
104
0
120
63
180
288
55
484
81
4
49
288
288
0
169
24
285
1
48
4
54
210
525
0
8
18
78
625
441
18
48
30
90
1
576
225
16
624
304
0
0
...

result:

ok 10000 numbers

Test #6:

score: -100
Wrong Answer
time: 32ms
memory: 40648kb

input:

10000
16 17
13 12
13 9
8 10
13 15
10 2
13 7
7 14
2 11
6 9
7 11
1 3
8 7
9 1
6 7
1 11
6 4
14 13
10 3
6 2
9 6
2 3
19 3
1 18
14 4
2 2
16 1
1 2
20 24
15 7
1 16
7 5
15 9
5 8
11 6
18 11
18 17
4 15
2 17
11 5
15 14
20 7
3 13
10 10
7 14
20 3
16 16
17 17
19 17
4 16
17 7
16 14
7 1
31 32
26 6
6 3
7 31
12 18
11 9...

output:

70
49
256
225
72
420
625
0
48
132
0
0
70
112
132
0
24
0
182
8
238
2
342
0
32
0
72
357
0
60
156
399
126
784
72
7
266
25
783
28
208
529
20
104
441
30
255
0
1
725
0
16
324
16
0
0
70
36
2
210
40
224
28
289
484
54
380
255
0
20
1024
221
0
418
81
2
625
420
36
0
0
900
16
378
324
380
182
756
784
378
156
56
0...

result:

wrong answer 8396th numbers differ - expected: '154', found: '324'