QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#21720#2832. Graph TheoryQyc_AK_NOI2022#AC ✓838ms6132kbC++145.9kb2022-03-08 14:31:502022-05-08 03:59:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 03:59:21]
  • 评测
  • 测评结果:AC
  • 用时:838ms
  • 内存:6132kb
  • [2022-03-08 14:31:50]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<stack>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<random>
#include<chrono>
#include<deque>
#include<cassert>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<vector>
#define fi first
#define se second
#define pb push_back
#define mp std::make_pair
#define ulf Useful_little_function
#define abs ccf
#define inline __attribute__((always_inline))inline
#define INF (0x3f3f3f3f)
#define INT_INF (2147483647)
#define LLINF (0x3f3f3f3f3f3f3f3fll)
#define LL_INF (9223372036854775807)
#define memset __builtin_memset
#define popcount __builtin_popcount
std::mt19937 rnd(std::chrono::system_clock::now().time_since_epoch().count());
typedef long long ll;
typedef std::pair<int,int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
inline void file(){freopen(".in","r",stdin);freopen(".out","w",stdout);}
namespace IO{
    #define BUF_SIZE (1<<16)
    #define OUT_SIZE (1<<16)
    bool IOerror=0;
    inline char nc(){static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;if(p1==pend){p1=buf;pend=buf+fread(buf,1,BUF_SIZE,stdin);if(pend==p1)return IOerror=1,-1;}return *p1++;}
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
    inline void read(int &x){bool sign=0;char ch=nc();x=0;for(;blank(ch);ch=nc());if(IOerror)return;if(ch=='-')sign=1,ch=nc();for(;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';if(sign)x=-x;}
    inline void read(ll &x){bool sign=0;char ch=nc();x=0;for(;blank(ch);ch=nc());if(IOerror)return;if(ch=='-')sign=1,ch=nc();for(;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';if(sign)x=-x;}
    inline void read(double &x){bool sign=0;char ch=nc();x=0;for(;blank(ch);ch=nc());if(IOerror)return;if(ch=='-')sign=1,ch=nc();for(;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';if(ch=='.'){double tmp=1;ch=nc();for(;ch>='0'&&ch<='9';ch=nc())tmp/=10.0,x+=tmp*(ch-'0');}if(sign)x=-x;}
    inline void read(char *s){char ch=nc();for(;blank(ch);ch=nc());if(IOerror)return;for(;!blank(ch)&&!IOerror;ch=nc())*s++=ch;*s=0;}
    inline void read(char &c){for(c=nc();blank(c);c=nc());if(IOerror){c=-1;return;}}
    struct Ostream_fwrite{
        char *buf,*p1,*pend;
        Ostream_fwrite(){buf=new char[BUF_SIZE];p1=buf;pend=buf+BUF_SIZE;}
        inline void out(char ch){if(p1==pend){fwrite(buf,1,BUF_SIZE,stdout);p1=buf;}*p1++=ch;}
        inline void print(int x){static char s[15],*s1;s1=s;if(!x)*s1++='0';if(x<0)out('-'),x=-x;while(x)*s1++=x%10+'0',x/=10;while(s1--!=s)out(*s1);}
        inline void println(int x){print(x);out('\n');}
        inline void print(ll x){static char s[25],*s1;s1=s;if(!x)*s1++='0';if(x<0)out('-'),x=-x;while(x)*s1++=x%10+'0',x/=10;while(s1--!=s)out(*s1);}
        inline void println(ll x){print(x);out('\n');}
        inline void print(double x,int y){//y<18
			static ll mul[]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000LL,100000000000LL,1000000000000LL,10000000000000LL,100000000000000LL,1000000000000000LL,10000000000000000LL,100000000000000000LL};
            if(x<-1e-12)out('-'),x=-x;x*=mul[y];ll x1=(ll)floor(x);if(x-floor(x)>=0.5)++x1;ll x2=x1/mul[y],x3=x1-x2*mul[y];print(x2);if(y>0){out('.');for(size_t i=1;i<y&&x3*mul[i]<mul[y];out('0'),++i);print(x3);}
        }
        inline void println(double x,int y){print(x,y);out('\n');}
        inline void print(char *s){while(*s)out(*s++);}
        inline void println(char *s){while(*s)out(*s++);out('\n');}
        inline void flush(){if(p1!=buf){fwrite(buf,1,p1-buf,stdout);p1=buf;}}
        ~Ostream_fwrite(){flush();}
    }Ostream;
    inline void print(int x){Ostream.print(x);}
    inline void println(int x){Ostream.println(x);}
    inline void print(char x){Ostream.out(x);}
    inline void println(char x){Ostream.out(x);Ostream.out('\n');}
    inline void print(ll x){Ostream.print(x);}
    inline void println(ll x){Ostream.println(x);}
    inline void print(double x,int y){Ostream.print(x,y);}
    inline void println(double x,int y){Ostream.println(x,y);}
    inline void print(char *s){Ostream.print(s);}
    inline void println(char *s){Ostream.println(s);}
    inline void println(){Ostream.out('\n');}
    inline void flush(){Ostream.flush();}
    #undef OUT_SIZE
    #undef BUF_SIZE
}using namespace IO;
namespace Little_function{
	inline int abs(int x){return x<0?-x:x;}
	inline ll abs(ll x){return x<0?-x:x;}
	inline double abs(double x){return x<0?-x:x;}
	inline int max(const int &a,const int &b){return a>b?a:b;}
	inline ll max(const ll &a,const ll &b){return a>b?a:b;}
	inline double max(const double &a,const double &b){return a>b?a:b;}
	inline int min(const int &a,const int &b){return a<b?a:b;}
	inline ll min(const ll &a,const ll &b){return a<b?a:b;}
	inline double min(const double &a,const double &b){return a<b?a:b;}
	inline void swap(int &x,int &y){x^=y^=x^=y;}
	inline void swap(ll &x,ll &y){x^=y^=x^=y;}
	inline void swap(double &x,double &y){double t=x;x=y,y=t;}
	inline int madd(const int &a,const int &b,const int &p){return (a+b)%p;}
	inline int mdel(const int &a,const int &b,const int &p){return (a-b<0?a-b+p:a-b);}
	int gcd(int a,int b){return !b?a:gcd(b,a%b);}
	ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
}using namespace Little_function;
const int N=2e5+13;
int n,m,a[N],b[N],c[N];
bool check(int lim){
	memset(c,0,sizeof c);
	for(int i=1;i<=m;++i){
		int len1=(b[i]-a[i]),len2=n-len1;
		if(len1>lim&&len2>lim) return 0;
		if(len2<=lim){c[a[i]]++,c[b[i]]--;}
		if(len1<=lim){c[1]++,c[a[i]]--,c[b[i]]++;}
	}
	int sum=0;
	for(int i=1;i<=n;++i){
		sum+=c[i];
		if(sum==m) return 1;
	}
	return 0;
}
int main(){
	while(scanf("%d",&n)==1){
		scanf("%d",&m);
		for(int i=1;i<=m;++i){
			scanf("%d%d",&a[i],&b[i]);
			if(a[i]>b[i]) swap(a[i],b[i]);
		}
		int l=0,r=n;
		while(l<r){
			int mid=(l+r)>>1;
			if(check(mid)) r=mid;
			else l=mid+1;
		}
		println(l);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 4544kb

input:

3 2
1 2
2 3
3 2
1 1
2 2
3 3
1 2
2 3
3 1

output:

1
0
2

result:

ok 3 lines

Test #2:

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

input:

2 1
1 2

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 838ms
memory: 4456kb

input:

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

output:

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

result:

ok 10000 lines

Test #4:

score: 0
Accepted
time: 183ms
memory: 4428kb

input:

190 27
72 104
45 123
187 67
105 21
52 179
141 79
107 23
111 166
27 186
35 15
1 59
48 67
105 153
51 92
92 178
149 98
86 153
144 100
13 100
186 91
124 153
24 116
75 15
105 18
137 52
150 129
109 100
106 100
15 36
52 105
7 19
40 62
19 95
26 90
67 55
14 104
90 45
59 41
78 61
100 96
77 55
75 85
13 76
50 1...

output:

95
53
25
77
43
78
94
14
83
35
24
70
46
17
12
38
6
19
21
68
45
87
40
28
38
52
11
10
11
26
48
80
92
48
94
56
12
22
19
1
45
60
9
59
82
44
12
85
24
34
25
90
71
60
43
16
74
9
36
83
19
54
37
76
82
53
21
30
18
86
15
91
63
45
18
22
13
53
71
49
77
67
25
58
44
67
28
87
44
6
67
12
34
93
12
33
21
67
69
100
96
7...

result:

ok 1000 lines

Test #5:

score: 0
Accepted
time: 41ms
memory: 4332kb

input:

631 403
564 132
336 393
68 11
23 519
24 399
463 382
550 163
557 333
404 578
139 46
576 72
207 424
408 224
509 551
12 389
119 490
239 462
531 363
295 607
87 91
525 469
493 133
22 450
325 557
348 29
594 380
495 540
45 387
452 64
562 585
539 403
516 212
511 153
347 186
59 51
475 453
426 463
363 570
127...

output:

315
105
859
936
348
811
510
237
852
571
482
496
996
192
445
19
840
235
569
915
267
977
587
468
574
461
412
436
89
794
314
656
693
794
640
15
43
885
667
891
559
237
275
268
43
774
197
914
510
817
264
406
813
781
657
410
665
193
523
943
846
427
985
200
592
786
502
804
308
615
395
814
455
585
990
93
27...

result:

ok 100 lines

Test #6:

score: 0
Accepted
time: 48ms
memory: 5976kb

input:

33612 200000
24258 24258
16589 16578
27435 27434
12485 12483
27768 27779
25352 25365
7899 7890
21677 21679
18384 18403
8639 8647
25720 25731
12560 12553
6818 6821
6737 6721
756 738
24289 24278
25287 25299
15980 15968
30378 30385
16423 16439
8410 8430
13605 13623
8786 8779
15942 15943
8070 8086
1114 ...

output:

20

result:

ok single line: '20'

Test #7:

score: 0
Accepted
time: 46ms
memory: 6132kb

input:

200000 200000
108194 108177
107888 107907
151974 151986
145582 145564
160644 160655
6520 6512
27546 27560
54120 54109
23774 23761
139151 139169
3715 3704
37270 37261
27979 27961
68030 68029
172350 172337
136551 136539
71687 71702
72681 72683
170998 171009
102032 102015
86070 86050
49785 49795
70532 ...

output:

20

result:

ok single line: '20'

Test #8:

score: 0
Accepted
time: 49ms
memory: 6096kb

input:

200000 200000
58978 58965
179601 179599
46881 46885
85872 85892
35453 35444
48837 48846
169811 169812
4905 4924
67871 67891
33498 33485
80041 80044
8614 8597
102554 102541
171922 171932
62674 62672
107682 107674
35596 35578
172014 172010
99018 99003
66233 66216
135849 135865
176225 176211
149831 149...

output:

199980

result:

ok single line: '199980'

Test #9:

score: 0
Accepted
time: 39ms
memory: 6064kb

input:

2619 200000
91 2546
2167 2178
1378 1382
2607 101
1142 1142
1426 1254
284 391
633 612
796 815
1279 1252
462 289
2341 2497
2249 2414
1888 1808
795 613
644 704
107 220
906 865
1820 1871
64 21
2035 2127
934 1128
1898 1707
2521 2593
2483 2532
1056 1006
2058 2085
5 2579
1875 2017
1930 1857
1365 1510
1373 ...

output:

200

result:

ok single line: '200'

Test #10:

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

input:

200000 200000
77541 77668
193849 193974
4353 4529
126362 126199
170504 170429
79476 79313
137113 137023
18179 17981
86106 85988
150401 150435
77291 77232
4807 4752
33154 33321
44592 44553
51663 51607
125340 125332
161780 161964
170246 170105
136712 136881
12249 12121
56432 56489
59541 59740
193372 1...

output:

200

result:

ok single line: '200'

Test #11:

score: 0
Accepted
time: 48ms
memory: 5984kb

input:

200000 200000
144945 144926
43570 43483
102995 103184
48655 48633
100760 100735
21871 21758
186954 186754
106156 105971
117724 117552
93684 93784
185343 185268
169480 169516
153231 153347
188641 188643
174891 174950
184805 184692
55358 55429
143290 143290
18832 18932
1717 1685
76283 76399
140911 141...

output:

199931

result:

ok single line: '199931'

Test #12:

score: 0
Accepted
time: 44ms
memory: 6096kb

input:

2753 200000
1567 2447
146 2396
2105 289
1428 1582
91 414
573 2195
688 2432
1753 27
2115 80
1108 333
1721 2414
247 1855
2301 2234
1442 1525
1733 1723
556 2150
1523 1325
2088 2554
398 2535
2302 426
1859 1877
1249 1743
774 2726
1550 2584
2131 1742
1070 1208
1564 2448
2053 251
2264 2485
651 622
384 2653...

output:

1376

result:

ok single line: '1376'

Test #13:

score: 0
Accepted
time: 49ms
memory: 6016kb

input:

200000 200000
144299 142443
170759 170168
13598 12363
70699 72000
174069 174010
127232 127804
181968 182452
167743 168825
181209 181165
40023 39654
76878 75581
121506 121982
7371 5875
73566 72948
67819 67998
55909 55375
194498 193918
38968 37706
106061 104788
34779 32791
98340 97552
6048 7644
55091 ...

output:

2000

result:

ok single line: '2000'

Test #14:

score: 0
Accepted
time: 59ms
memory: 5984kb

input:

200000 200000
109908 111184
1210 958
85545 86647
31353 30839
31365 30782
177487 176217
42028 40035
196307 194489
73688 74795
182151 184084
145295 145127
121640 122496
15511 17387
197444 199053
23503 23378
102291 101558
104545 104612
153364 154225
108691 106877
97684 97832
11098 12441
163721 163949
1...

output:

199772

result:

ok single line: '199772'

Test #15:

score: 0
Accepted
time: 41ms
memory: 6072kb

input:

112411 200000
89356 99748
79269 70862
74296 62562
33543 18084
67193 71296
68596 72711
111513 13580
99654 110235
49334 29547
103334 89429
8865 21235
3207 103751
69732 81353
91925 86018
36967 31057
3249 106257
87378 93252
19590 6945
55442 43833
25226 16247
63015 66887
105933 2554
50448 46113
105629 65...

output:

20000

result:

ok single line: '20000'

Test #16:

score: 0
Accepted
time: 47ms
memory: 6084kb

input:

200000 200000
100188 117578
163374 179342
169201 166560
11752 27291
174489 157952
13491 23417
41257 48023
108455 124900
68096 55019
182211 170960
23850 21033
24413 6528
21765 34031
197057 197239
3153 9876
47787 48251
161869 171159
1161 181706
15492 24716
129668 149299
1941 184718
127162 122023
62596...

output:

20000

result:

ok single line: '20000'

Test #17:

score: 0
Accepted
time: 56ms
memory: 6080kb

input:

200000 200000
31666 20847
168453 183493
138993 150388
6477 7227
142698 137815
73496 88744
69245 56191
18561 6261
23384 41731
54763 70117
23732 5160
121127 115549
177804 173435
49120 56551
50051 42413
134546 147131
152984 156111
14905 8669
22596 21785
135209 116113
21201 32672
47485 33848
177644 1773...

output:

199368

result:

ok single line: '199368'

Test #18:

score: 0
Accepted
time: 34ms
memory: 6132kb

input:

87703 200000
80269 32687
10933 4546
44361 77176
43490 62542
49536 11246
56823 28363
57799 23421
52882 9097
44783 62254
66037 31497
50453 31095
25133 46893
52253 42283
44524 8181
69219 77337
60241 55350
46284 3368
23212 53223
27892 64911
3869 27571
15445 56449
32834 60187
69776 40979
46421 47264
3269...

output:

43851

result:

ok single line: '43851'

Test #19:

score: 0
Accepted
time: 41ms
memory: 6064kb

input:

200000 200000
98510 170535
40097 35353
120488 107445
23639 84916
152921 190097
51856 23037
130384 118643
117146 157081
122856 38085
177902 184094
140568 11002
167731 187451
153245 84753
158043 110222
82352 173086
87356 27578
88867 63640
188240 127410
121909 57534
126943 83420
175258 199128
49462 229...

output:

100000

result:

ok single line: '100000'

Test #20:

score: 0
Accepted
time: 60ms
memory: 6132kb

input:

200000 200000
118991 43971
187851 190270
15034 165631
163547 48913
80193 171641
136336 90969
18504 164685
89554 64919
73511 66687
113792 160526
68659 86357
79728 126920
167076 27572
140197 20159
83429 187559
32821 130189
132836 105476
97755 3552
71168 117112
169796 72861
103274 169554
59972 142947
7...

output:

198696

result:

ok single line: '198696'