QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#327839#1844. CactusExplodingKonjacAC ✓119ms71072kbC++206.0kb2024-02-15 14:58:152024-02-15 14:58:16

Judging History

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

  • [2024-02-15 14:58:16]
  • 评测
  • 测评结果:AC
  • 用时:119ms
  • 内存:71072kb
  • [2024-02-15 14:58:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define OPENIOBUF

namespace FastIO
{

class FastIOBase
{
 protected:
#ifdef OPENIOBUF
	static const int BUFSIZE=1<<16;
	char buf[BUFSIZE+1];
	int buf_p=0;
#endif
	FILE *target;
	FastIOBase(FILE *f): target(f){}
	~FastIOBase()=default;
 public:
#ifdef OPENIOBUF
	virtual void flush()=0;
#endif
};

class FastOutput final: public FastIOBase
{
 public:
	FastOutput(FILE *f=stdout): FastIOBase(f) {}
#ifdef OPENIOBUF
	~FastOutput() { flush(); }
	void flush() { fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
	void put(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
		putc(x,target);
#endif
	}
	FastOutput &operator <<(char x)
	{ return put(x),*this; }
	FastOutput &operator <<(const char *s)
	{ for(;*s;put(*(s++)));return *this; }
	FastOutput &operator <<(const std::string &s)
	{ return (*this)<<s.c_str(); }
	template<typename T>
	std::enable_if_t<std::is_integral<T>::value,FastOutput&> operator <<(T x)
	{
		if(x<0) return put('-'),(*this)<<(-x);
		char stk[std::numeric_limits<T>::digits10+1],*top=stk;
		do *(top++)=x%10+'0',x/=10; while(x);
		while(top!=stk) put(*(--top));
		return *this;
	}
	template<typename ...T>
	void writesp(T &&...x)
	{ std::initializer_list<int>{((*this)<<(x),put(' '),0)...}; }
	template<typename ...T>
	void writeln(T &&...x)
	{ std::initializer_list<int>{((*this)<<(x),put('\n'),0)...}; }
	template<typename Iter>
	std::enable_if_t<std::is_base_of<
		std::forward_iterator_tag,
		typename std::iterator_traits<Iter>::iterator_category>
	::value> writesp(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<' '; }
	template<typename Iter>
	std::enable_if_t<std::is_base_of<
		std::forward_iterator_tag,
		typename std::iterator_traits<Iter>::iterator_category>
	::value> writeln(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;

class FastInput final: public FastIOBase
{
 private:
	bool __eof;
 public:
	FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
	{ buf_p=BUFSIZE; }
	void flush() { buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
	bool eof()const { return buf[buf_p]==EOF; }
#else
	{}
	bool eof()const { return feof(target); }
#endif
	char get()
	{
		if(__eof) return EOF;
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		char ch=buf[buf_p++];
#else
		char ch=getc(target);
#endif
		return ~ch?ch:(__eof=true,EOF);
	}
	void unget(char c)
	{
		__eof=false;
#ifdef OPENIOBUF
		buf[--buf_p]=c;
#else
		ungetc(c,target);
#endif
	}
	explicit operator bool()const { return !__eof; }
	FastInput &operator >>(char &x)
	{ while(isspace(x=get()));return *this; }
	template<typename T>
	std::enable_if_t<std::is_integral<T>::value,FastInput&> operator >>(T &x)
	{
		char ch,sym=0;x=0;
		while(isspace(ch=get()));
		if(__eof) return *this;
		if(ch=='-') sym=1,ch=get();
		for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=get());
		return unget(ch),sym?x=-x:x,*this;
	}
	FastInput &operator >>(char *s)
	{
		while(isspace(*s=get()));
		if(__eof) return *this;
		for(;!isspace(*s) && !__eof;*(++s)=get());
		return unget(*s),*s='\0',*this;
	}
	FastInput &operator >>(std::string &s)
	{
		char str_buf[(1<<8)+1]={0},*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=get()));
		if(__eof) return *this;
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=get()) && !__eof;p++);
			if(p!=buf_end) break;
			s.append(str_buf);
		}
		unget(*p),*p='\0',s.append(str_buf);
		return *this;
	}
	template<typename ...T>
	void read(T &&...x)
	{ std::initializer_list<int>{((*this)>>(x),0)...}; }
	template<typename Iter>
	std::enable_if_t<std::is_base_of<
		std::forward_iterator_tag,
		typename std::iterator_traits<Iter>::iterator_category>
	::value> read(Iter begin,Iter end)
	{ while(begin!=end) (*this)>>*(begin++); }
}qin;

} // namespace FastIO
using FastIO::qin,FastIO::qout;

using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;

#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#define LOG(...) [](auto...){}(__VA_ARGS__)
#else
#define FILEIO(file)
#define LOG(...) fprintf(stderr,__VA_ARGS__)
#endif

constexpr int MAXN=3e5;

int n,m;
vector<int> G[MAXN+5];
vector<string> ans;
inline void report1(int x) { ans.push_back("1 "+to_string(x)); }
inline void report2() { ans.push_back("2"); }

int tot,top,cnt,deg[MAXN+5],dfn[MAXN+5],low[MAXN+5],stk[MAXN+5];
bool del[MAXN+5],inq[MAXN+5],vis[MAXN+5];
vector<int> ord,p[MAXN+5];
void tarjan(int u)
{
	dfn[u]=low[u]=++tot;
	stk[++top]=u;
	for(auto &v: G[u])
	{
		if(del[v]) continue;
		if(!dfn[v])
		{
			tarjan(v);
			low[u]=min(low[u],low[v]);
			if(low[v]!=dfn[u]) continue;
			ord.push_back(++cnt);
			p[cnt].push_back(u);
			deg[u]++;
			for(int x=0;x!=v;top--)
			{
				x=stk[top];
				p[cnt].push_back(x);
				deg[x]++;
			}
		}
		else low[u]=min(low[u],dfn[v]);
	}
}

int main()
{
	qin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		qin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
		deg[u]++,deg[v]++;
	}
	queue<int> q;
	for(int i=1;i<=n;i++)
		if(deg[i]&1) q.push(i),inq[i]=true;
	while(!q.empty())
	{
		int u=q.front();
		if(deg[u]&1)
		{
			for(auto &v: G[u])
				if(!del[v] && ((--deg[v])&1) && !inq[v])
					q.push(v),inq[v]=true;
			del[u]=true;
			report1(u);
		}
		q.pop(),inq[u]=false;
	}
	fill(deg+1,deg+n+1,0);
	for(int i=1;i<=n;i++)
		if(!del[i] && !dfn[i]) tarjan(i);
	report2();
	for(auto &id: ord)
	{
		auto it=find_if(p[id].begin(),p[id].end(),[](int x) {
			return deg[x]>1;
		});
		rotate(p[id].begin(),it,p[id].end());
		int sz=p[id].size();
		for(int i=1;i<sz;i++)
			report1(p[id][i]+((i&1)?0:n)),vis[p[id][i]]=true;
		report1(p[id][1]+n);
		report1(p[id][sz-1]+((sz&1)?0:n));
		for(auto &u: p[id]) deg[u]--;
	}
	for(int i=1;i<=n;i++) if(!vis[i]) report1(i);
	qout<<"0 "<<ans.size()<<'\n';
	for(auto &s: ans) qout<<s<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 3
1 2
1 3
2 3

output:

0 6
2
1 3
1 5
1 6
1 2
1 1

result:

ok You are right!

Test #2:

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

input:

7 7
1 2
1 3
2 3
2 4
2 5
3 6
3 7

output:

0 14
1 4
1 5
1 6
1 7
2
1 3
1 9
1 10
1 2
1 1
1 4
1 5
1 6
1 7

result:

ok You are right!

Test #3:

score: 0
Accepted
time: 80ms
memory: 60848kb

input:

300000 368742
1 143504
1 234282
2 91276
2 296320
3 274816
4 212293
4 258214
5 253489
5 295826
6 96521
6 252745
6 267103
6 269879
7 5293
7 295586
8 44304
8 57067
8 233291
9 190526
10 18682
11 7440
12 24695
12 172561
12 243692
12 280316
13 80152
13 268749
14 146394
14 207280
15 151280
15 226848
16 458...

output:

0 525865
1 3
1 8
1 9
1 10
1 11
1 16
1 20
1 21
1 25
1 28
1 29
1 30
1 32
1 33
1 34
1 41
1 42
1 43
1 44
1 47
1 48
1 53
1 54
1 55
1 57
1 59
1 62
1 65
1 73
1 75
1 77
1 80
1 81
1 87
1 88
1 94
1 95
1 101
1 102
1 103
1 106
1 112
1 123
1 128
1 129
1 133
1 136
1 137
1 138
1 140
1 141
1 143
1 145
1 146
1 150
1...

result:

ok You are right!

Test #4:

score: 0
Accepted
time: 86ms
memory: 42384kb

input:

221155 322762
1 16446
1 214165
2 22590
2 67599
2 77971
2 173665
3 93601
3 218260
4 78445
4 126476
5 85674
5 129671
6 105765
6 161364
7 16742
7 19554
7 28037
7 51308
7 57193
7 151371
7 173612
7 218897
8 50830
8 178401
9 36068
9 198155
10 31227
10 57914
11 104822
11 196836
12 57848
12 129309
13 17006
...

output:

0 424372
2
1 85270
1 239806
1 306425
1 18651
1 210938
1 269691
1 432093
1 48536
1 179493
1 236953
1 400648
1 15798
1 163470
1 355214
1 384625
1 134059
1 75265
1 270504
1 823
1 296420
1 221978
1 37551
1 237273
1 258706
1 16118
1 115198
1 279288
1 336353
1 58133
1 168446
1 233484
1 389601
1 12329
1 39...

result:

ok You are right!

Test #5:

score: 0
Accepted
time: 118ms
memory: 68576kb

input:

299999 449997
1 135132
1 274953
2 18542
2 217508
3 47624
3 205183
4 121104
4 270541
5 117846
5 249889
6 272286
6 286376
7 63903
7 89777
8 153806
8 271509
9 49792
9 220343
10 4543
10 293635
11 99727
11 261001
12 29177
12 108823
13 119446
13 183797
14 210754
14 247874
15 53747
15 122774
15 179117
15 2...

output:

0 599998
2
1 175523
1 460131
1 475522
1 160132
1 170656
1 329177
1 470655
1 29178
1 245181
1 330052
1 545180
1 30053
1 299414
1 339277
1 599413
1 39278
1 130566
1 350821
1 430565
1 50822
1 281548
1 498295
1 581547
1 198296
1 266591
1 314502
1 566590
1 14503
1 283034
1 336697
1 583033
1 36698
1 19916...

result:

ok You are right!

Test #6:

score: 0
Accepted
time: 80ms
memory: 44828kb

input:

300000 399999
1 215446
1 231704
2 115181
2 170051
3 1993
3 176144
4 18113
5 34133
5 53137
6 163395
6 256615
7 39049
7 128932
8 193977
8 205442
9 2810
9 260471
10 169593
10 278417
11 56849
11 139915
12 78729
12 164991
13 55416
13 62164
14 195504
14 254962
15 41739
15 143315
16 61905
16 244260
16 2772...

output:

0 513330
1 4
1 16
1 18
1 22
1 29
1 30
1 32
1 35
1 39
1 47
1 49
1 56
1 61
1 62
1 65
1 66
1 74
1 77
1 78
1 79
1 86
1 87
1 99
1 100
1 101
1 103
1 107
1 110
1 116
1 127
1 135
1 140
1 142
1 143
1 146
1 148
1 149
1 150
1 156
1 158
1 161
1 164
1 172
1 179
1 181
1 187
1 188
1 192
1 195
1 198
1 200
1 204
1 2...

result:

ok You are right!

Test #7:

score: 0
Accepted
time: 119ms
memory: 71072kb

input:

299999 449997
1 207233
1 249849
2 26483
2 120133
3 48410
3 154146
3 264694
3 276131
4 33119
4 235166
5 104107
5 256329
6 121201
6 153902
7 217994
7 249799
8 98561
8 149095
8 161763
8 244331
9 113135
9 263126
10 78235
10 93112
11 58805
11 104743
11 135998
11 140583
11 199748
11 227329
12 34054
12 124...

output:

0 599998
2
1 23193
1 313993
1 323192
1 13994
1 263221
1 519656
1 563220
1 219657
1 76491
1 314755
1 376490
1 14756
1 170147
1 377349
1 470146
1 77350
1 184005
1 318266
1 484004
1 18267
1 274750
1 310371
1 574749
1 10372
1 170256
1 385619
1 470255
1 85620
1 205577
1 370495
1 505576
1 70496
1 177508
1...

result:

ok You are right!

Test #8:

score: 0
Accepted
time: 85ms
memory: 49944kb

input:

280291 392867
1 18749
1 136817
2 63519
2 159662
2 172896
2 251761
3 1878
3 142748
4 203284
4 228584
5 15844
5 50208
6 136817
6 245137
7 64955
7 165499
8 136817
8 220201
9 136817
9 191205
10 136817
10 192877
11 139542
11 162473
12 57326
12 190877
13 33859
13 153427
14 110791
14 136817
15 16389
15 864...

output:

0 505446
2
1 245137
1 280297
1 525428
1 6
1 220201
1 280299
1 500492
1 8
1 191205
1 280300
1 471496
1 9
1 192877
1 280301
1 473168
1 10
1 110791
1 280305
1 391082
1 14
1 17196
1 280317
1 297487
1 26
1 205340
1 280321
1 485631
1 30
1 240440
1 280322
1 520731
1 31
1 38981
1 280327
1 319272
1 36
1 2377...

result:

ok You are right!

Test #9:

score: 0
Accepted
time: 107ms
memory: 69064kb

input:

292995 410094
1 71999
1 169963
2 98256
2 132856
3 132856
3 165225
4 82003
4 132856
5 132364
5 160935
6 35335
6 147436
7 132856
7 255985
8 132856
8 200164
9 4463
9 156552
10 2320
10 99646
11 132856
11 185279
12 110686
12 285870
13 73136
13 275400
14 121746
14 132856
15 153856
15 278178
16 83552
16 21...

output:

0 527196
2
1 177036
1 469916
1 470031
1 176921
1 218881
1 370454
1 511876
1 77459
1 168011
1 319081
1 461006
1 26086
1 292785
1 401524
1 585780
1 108529
1 162620
1 302823
1 455615
1 9828
1 66022
1 355265
1 359017
1 62270
1 91087
1 372908
1 384082
1 79913
1 112342
1 328972
1 405337
1 35977
1 171517
1...

result:

ok You are right!

Test #10:

score: 0
Accepted
time: 65ms
memory: 44744kb

input:

300000 403707
1 129294
1 278573
2 11106
2 129294
3 184237
3 221196
4 55817
4 100929
4 136405
4 238314
5 31450
5 186997
6 4795
7 129294
7 163574
8 61455
8 129294
9 21984
9 129294
10 231237
11 129294
11 228549
12 129294
12 224390
13 19505
13 26574
14 55849
14 98378
15 23106
16 4025
16 100577
17 67090
...

output:

0 497625
1 6
1 10
1 15
1 19
1 20
1 25
1 26
1 37
1 43
1 44
1 63
1 64
1 65
1 66
1 68
1 69
1 71
1 80
1 84
1 85
1 91
1 102
1 103
1 104
1 109
1 110
1 112
1 116
1 117
1 120
1 133
1 142
1 146
1 147
1 152
1 153
1 155
1 173
1 175
1 176
1 177
1 178
1 186
1 192
1 199
1 208
1 217
1 221
1 222
1 227
1 228
1 231
1...

result:

ok You are right!

Test #11:

score: 0
Accepted
time: 1ms
memory: 3564kb

input:

1 0

output:

0 2
2
1 1

result:

ok You are right!

Test #12:

score: 0
Accepted
time: 77ms
memory: 40304kb

input:

255596 313062
1 10655
1 15889
1 35851
1 220010
1 243820
2 236476
3 75462
3 240876
3 241881
4 164691
5 112681
6 31313
6 40322
6 89447
6 199617
7 78108
7 249785
8 180866
8 225929
9 26444
10 209074
11 108986
12 147579
12 165165
13 53313
13 182814
13 230088
14 124147
15 73182
15 98755
15 212191
16 98391...

output:

0 442867
1 1
1 2
1 3
1 4
1 5
1 9
1 10
1 11
1 13
1 14
1 15
1 18
1 19
1 22
1 24
1 25
1 27
1 28
1 29
1 31
1 32
1 33
1 34
1 35
1 37
1 38
1 39
1 40
1 42
1 43
1 46
1 47
1 48
1 50
1 51
1 55
1 56
1 58
1 59
1 60
1 63
1 65
1 67
1 68
1 69
1 70
1 71
1 72
1 73
1 74
1 75
1 77
1 78
1 79
1 82
1 86
1 87
1 88
1 89
1 ...

result:

ok You are right!

Test #13:

score: 0
Accepted
time: 82ms
memory: 48420kb

input:

244001 330353
1 33864
1 90721
1 120604
1 122898
1 195228
1 211057
2 9529
2 118870
3 35564
3 229469
4 81097
4 236945
5 47476
5 223470
6 46769
6 48597
7 49304
7 146411
7 154996
7 220507
8 14839
8 162760
9 85423
9 114698
10 4239
10 32108
10 39949
10 85700
11 160326
11 205183
12 25068
12 156392
13 13985...

output:

0 416708
2
1 123465
1 304201
1 367466
1 60200
1 209493
1 428801
1 453494
1 184800
1 210394
1 418008
1 454395
1 174007
1 152288
1 268718
1 396289
1 24717
1 80217
1 288154
1 324218
1 44153
1 241709
1 358246
1 485710
1 114245
1 184637
1 401323
1 428638
1 157322
1 110373
1 423411
1 37736
1 354374
1 2817...

result:

ok You are right!