QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#760958#7898. I Just Want... One More...podysTL 2589ms25368kbC++235.1kb2024-11-18 20:22:342024-11-18 20:22:35

Judging History

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

  • [2024-11-18 20:22:35]
  • 评测
  • 测评结果:TL
  • 用时:2589ms
  • 内存:25368kb
  • [2024-11-18 20:22:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define uint unsigned long long
#define endl '\n'
// #define ll __int128
namespace OOO
{
	void fast_io()
	{
		std::ios::sync_with_stdio(false);
		std::cin.tie(0);
		std::cout.tie(0);
	}
	int get_int()
	{
	    int x=0;
	    bool y=0;
	    char c=getchar();
	    for(;c<'0'||c>'9';c=getchar())
	    {
	        if(c=='-')
	        {
	            y=1;
	        }
	    }
	    for(;c>='0'&&c<='9';c=getchar())
	    {
	        x=(x<<3)+(x<<1)+c-'0';
	    }
	    return y?-x:x;
	}
	void out_int(int x)
	{
		if(x==0)
		{
			putchar('0');
			return;
		}
		int s=1;
		for(;s<=x;s=(s<<3)+(s<<1))
		{
		}
		for(s/=10;s;s/=10)
		{
			putchar(x/s-x/(s*10)*10+'0');
		}
	}
	int fast_pow(int a,int b,int mod)
    {
        int ans=1;
        if(a>mod)
        {
        	a%=mod;
		}
        for(;b;b>>=1)
        {
            if(b&1)
            {
                ans=ans*a;
				if(ans>mod)
            	{
            		ans%=mod;
				}
            }
            a=a*a;
            if(a>mod)
            {
            	a%=mod;
			}
        }
        return ans;
    }
}using namespace OOO;
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
class Edge
{
	public:
		int st,to;
		int num;
		int nxt;
		Edge(int _st=0,int _to=0,int _num=0,int _nxt=0)
		:st(_st),to(_to),num(_num),nxt(_nxt)
		{
		}
};
class Road
{
	public:
		vector<Edge> edge;
		vector<int> tope;
		int cnt;
		
		void init(int p_num=0,int edge_num=0)
		{
			edge=vector<Edge>(edge_num+1);
			tope=vector<int>(p_num+1,0);
			cnt=0;
		}
		int newnode()
		{
			if(cnt==edge.size()-1)
			{
				edge.push_back(Edge());
			}
			return ++cnt;
		}
		void addedge(int a,int b,int num=0)
		{
			int s=max(a,b);
			if(s>=tope.size())
			{
				tope.resize(tope.size()*2);
			}
			edge[newnode()]=Edge(a,b,num,tope[a]);
			tope[a]=cnt;
		}
		void twoadd_none(int a,int b,int num=0)
		{
			addedge(a,b,num);
			addedge(b,a,0);
		}
		void twoadd_yes(int a,int b,int num=0)
		{
			addedge(a,b,num);
			addedge(b,a,num);
		}
		int other(int x)
		{
			if(x%2)
			{
				return x+1;
			}
			return x-1;
		}
};
namespace ZDL
{
	const int inf=1e9;
	class node
	{
		public:
			int deep;
			int now;
	};
	int n;
	int start,end;
	vector<node> th;
	Road *road;
	bool bfs()
	{
		for(int i=0;i<=n;i++)
		{
			th[i].deep=inf;
			th[i].now=(*road).tope[i];
		}
		queue<int> q;
		th[start].deep=0;
		q.push(start);
		for(;q.size();)
		{
			int t=q.front();
			q.pop();
			for(int i=(*road).tope[t];i;i=(*road).edge[i].nxt)
			{
				int to=(*road).edge[i].to;
				if((*road).edge[i].num>0&&th[to].deep==inf)
				{
					q.push(to);
					th[to].deep=th[t].deep+1;
				}
			}
		}
		return th[end].deep<inf;
	}
	int dfs(int w,int sum)
	{
		if(w==end||!sum)
		{
			return sum;
		}
		int flow=0;
		for(int i=th[w].now;i&&sum;i=(*road).edge[i].nxt)
		{
			th[w].now=i;
			int to=(*road).edge[i].to;
			if((*road).edge[i].num>0&&th[to].deep==th[w].deep+1)
			{
				int use=dfs(to,min(sum,(*road).edge[i].num));
				if(use)
				{
					(*road).edge[i].num-=use;
					(*road).edge[(*road).other(i)].num+=use;
					sum-=use;
					flow+=use;
				}else
				{
					th[to].deep=inf;
				}
			}
		}
		return flow;
	}
	int solve(Road *_road,int _n,int _start,int _end)
	{
		start=_start;end=_end;
		n=_n;
		th=vector<node>(n+1);
		road=_road;
		int flow=0;
		for(;bfs();)
		{
			flow+=dfs(start,inf);
		}
		return flow;
	}
}
int n,m;
Road road;
ll has(int a,int b){
    return 100000000ll*a+b;
}
void read()
{
	n=get_int();m=get_int();
	road.init(2*n+1,2*(m+2*n));
	int a,b;
	for(int i=1;i<=m;i++)
	{
		a=get_int();b=get_int();
		road.twoadd_none(a,b+n,1);
	}
}
vector<int> match;
void dfs(int w,vector<bool> &tag)
{
	tag[w]=1;
	for(int i=road.tope[w];i;i=road.edge[i].nxt)
	{
		int to=road.edge[i].to;
		if(to<1||to>2*n)
		{
			continue;
		}
		if(match[to]!=w&&!tag[match[to]])
		{
			dfs(match[to],tag);
		}
	}
}
int solve()
{
	int st=0,en=2*n+1;
	for(int i=1;i<=n;i++)
	{
		road.twoadd_none(st,i,1);
		road.twoadd_none(i+n,en,1);
	}
	ZDL::solve(&road,2*n+1,st,en);
    
	match=vector<int>(2*n+1);
	for(int i=1;i<=road.cnt;i++)
	{
		int a=road.edge[i].st,b=road.edge[i].to;
		if(a>=1&&a<=n&&b>=n+1&&b<=2*n&&road.edge[i].num==0)
		{
			match[a]=b;match[b]=a;
		}
	}
    // int cnt1=0,cnt2=0;
    // for(int i=1;i<=n;i++){
    //     if(!match[i]){
    //         cnt1++;
    //     }
    // }
    // for(int i=n+1;i<=2*n;i++){
    //     if(!match[i]){
    //         cnt2++;
    //     }
    // }
    // cout<<cnt1<<" "<<cnt2<<endl;
	vector<bool> tag(2*n+1);
	for(int i=1;i<=2*n;i++)
	{
		if(!match[i]&&!tag[i])
		{
			dfs(i,tag);
		}
	}
	ll sl=0,sr=0;
	for(int i=1;i<=n;i++)
	{
		sl+=tag[i];
		sr+=tag[i+n];
	}
    cout<<sl*sr<<endl;
    return 0;
}
signed main()
{
//	freopen("t.txt","r",stdin);
	int t;
	t=get_int();
	for(;t;t--)
	{
		read();
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3812kb

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: 9ms
memory: 3620kb

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: 16ms
memory: 3676kb

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: 22ms
memory: 3668kb

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: 43ms
memory: 3664kb

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: 0
Accepted
time: 56ms
memory: 3660kb

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:

ok 10000 numbers

Test #7:

score: 0
Accepted
time: 58ms
memory: 3560kb

input:

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

output:

380
896
400
528
169
506
6
156
77
117
0
196
42
9
676
42
64
42
196
529
1024
132
729
784
44
400
0
30
96
2116
12
108
0
9
650
110
104
56
650
182
9
736
132
840
360
0
756
0
552
176
783
342
575
56
260
900
27
420
624
182
600
120
24
294
756
176
182
195
4
992
180
420
1722
14
400
16
306
6
96
154
440
638
120
104...

result:

ok 8195 numbers

Test #8:

score: 0
Accepted
time: 30ms
memory: 5552kb

input:

36
200 34923
19 6
111 30
122 58
130 123
79 127
51 17
77 115
180 115
135 39
59 17
6 92
164 83
191 61
135 194
21 53
118 131
99 32
115 128
136 73
149 164
80 61
143 172
183 67
178 34
141 11
63 158
198 99
136 181
199 154
51 124
181 143
196 73
129 36
103 26
20 132
113 184
70 21
54 95
151 64
20 85
9 118
31...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
39601
39601
39601
39601
0
39601
39601
39601
39601
39601
39601
39601
39601
39601
39601
39601
39601
39601

result:

ok 36 numbers

Test #9:

score: 0
Accepted
time: 45ms
memory: 7176kb

input:

47
300 73618
107 45
10 195
243 73
94 169
32 105
204 216
195 153
120 31
175 135
145 78
234 209
118 28
60 136
231 58
187 136
151 217
176 160
91 269
9 6
62 262
45 37
258 86
54 3
9 71
74 291
180 162
97 238
12 124
205 106
26 48
95 188
25 231
190 208
164 86
202 258
177 102
99 210
259 159
293 269
241 22
9 ...

output:

0
0
0
873
0
0
0
0
89401
0
0
89401
89401
89401
89401
89401
89401
89401
0
89401
89401
89401
89401
89401
89401
89401
89401
89401
1425
89401
89401
89401
89401
89401
89401
89401
89401
89401
89401
89401
89401
89401
2630
89401
89401
89401
46440

result:

ok 47 numbers

Test #10:

score: 0
Accepted
time: 132ms
memory: 9744kb

input:

11
5000 82272
1471 562
571 4062
2376 3538
1758 879
4355 4876
1765 2860
1225 3209
498 1448
589 4453
2795 2625
4702 2777
273 2409
3097 2177
673 1783
734 3503
4990 4311
30 3022
533 2902
4075 431
2471 1295
3584 3647
2082 4048
1501 4783
4753 2661
3844 931
1647 2404
2359 2724
3576 1480
4808 1718
33 4135
7...

output:

0
0
0
0
0
49690
24990001
19470126
24990001
9578925
24990001

result:

ok 11 numbers

Test #11:

score: 0
Accepted
time: 108ms
memory: 10276kb

input:

3
5000 100000
4850 2272
3933 2025
680 4017
1731 2777
4531 3649
604 3731
1982 3943
2572 2993
2689 3809
109 770
375 1878
915 1872
583 1674
801 1824
1372 4181
411 4222
997 2596
1434 4470
2509 4087
659 2740
2748 4217
2424 4669
2604 4588
3965 3636
309 3474
3324 1398
3977 653
4482 2406
1688 2064
3575 634
...

output:

0
0
0

result:

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

Test #12:

score: 0
Accepted
time: 668ms
memory: 13432kb

input:

3
20000 100000
5843 13706
18814 4687
10989 2645
892 6471
5919 3267
14982 10237
3234 13314
12232 1056
17492 12389
10544 4166
1334 15330
7890 19718
1836 7922
4165 4828
9696 3284
18660 10120
6016 3434
14062 9199
19740 11162
19175 17369
13737 3182
11573 977
16960 18709
3875 11593
6079 7904
13185 12275
6...

output:

3185208
3195666
2758896

result:

ok 3 number(s): "3185208 3195666 2758896"

Test #13:

score: 0
Accepted
time: 358ms
memory: 17320kb

input:

2
50000 100000
18349 36288
611 34094
39509 22068
13737 24139
8812 16539
32691 40514
30435 45795
27762 529
44702 5805
39757 39868
38374 6462
638 11003
32821 7502
39027 44967
10477 32684
36221 11712
20354 1895
7172 24249
8283 22070
19281 11370
29093 35378
3778 24398
576 18775
35881 31219
47184 4135
30...

output:

448726135
460334448

result:

ok 2 number(s): "448726135 460334448"

Test #14:

score: 0
Accepted
time: 28ms
memory: 19000kb

input:

3
100000 1
70384 39704
100000 1
40173 62941
100000 1
57956 44429

output:

9999800001
9999800001
9999800001

result:

ok 3 number(s): "9999800001 9999800001 9999800001"

Test #15:

score: 0
Accepted
time: 278ms
memory: 25360kb

input:

2
100000 100000
97142 35673
58757 30367
55923 72614
55158 23354
67397 53241
26699 86278
6870 57884
62293 89093
45762 37900
95133 32337
20986 90171
93467 7731
17953 61135
68736 14892
67506 42592
71949 48847
43288 98525
92346 96229
79284 38280
41392 18856
85050 38517
61551 82312
47956 98863
79913 7625...

output:

3224876460
3231126633

result:

ok 2 number(s): "3224876460 3231126633"

Test #16:

score: 0
Accepted
time: 291ms
memory: 25368kb

input:

2
100000 100000
46395 81745
22228 81651
98590 76796
15598 50394
67488 22778
21214 34195
11489 5442
93015 53334
33703 85678
78450 6720
34843 76187
54984 99888
99562 28301
12154 25162
9797 86024
98250 76151
10721 61304
12287 86339
95384 56394
82981 53310
19047 32305
41067 73852
81678 51522
93027 59381...

output:

3226894740
3220897533

result:

ok 2 number(s): "3226894740 3220897533"

Test #17:

score: 0
Accepted
time: 275ms
memory: 25368kb

input:

2
100000 100000
95649 84714
26916 65639
32746 13682
76037 10138
282 49212
91537 82112
59211 9897
23737 50279
97451 41968
53255 48399
81404 86396
49206 57453
89682 95467
31380 2729
95192 62161
33063 13855
45451 91379
75333 19554
68381 17613
81466 87764
77235 93389
55174 98096
72296 79989
6140 69921
2...

output:

3200670858
3198916512

result:

ok 2 number(s): "3200670858 3198916512"

Test #18:

score: 0
Accepted
time: 2589ms
memory: 20072kb

input:

2
49800 100000
40411 14598
25157 29927
19470 10822
27212 44376
44214 12243
11995 3393
2791 2984
16547 47689
2539 23678
14428 46503
23225 12084
18518 12402
20708 33807
16920 38483
40442 40878
1415 42844
24335 42524
35776 4646
33683 34828
33665 49711
47132 34603
29551 24533
47538 4967
47257 23671
5093...

output:

0
0

result:

ok 2 number(s): "0 0"

Test #19:

score: -100
Time Limit Exceeded

input:

2
49900 100000
9494 36435
2010 15660
17479 30725
12167 26217
19863 45716
10334 40493
41120 29000
28807 5568
8078 35845
14704 4154
18536 48875
7641 9003
32492 6004
10083 37961
23000 15168
38126 29062
18591 32285
24736 9855
20589 40264
10331 16560
35658 17680
22189 35001
5133 22182
13657 9361
20691 33...

output:


result: