QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#331555#1844. Cactussinsop90WA 259ms211388kbC++143.3kb2024-02-18 15:08:372024-02-18 15:08:37

Judging History

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

  • [2024-02-18 15:08:37]
  • 评测
  • 测评结果:WA
  • 用时:259ms
  • 内存:211388kb
  • [2024-02-18 15:08:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
int n, m, dfn[maxn], low[maxn], S[maxn], top, cnt, head[maxn], tot, col, deg[maxn], vis[maxn], visn[maxn], vism[maxn], visq[maxn];
queue<int> Q;
struct edge {
	int v, pre;
}e[maxn << 1];
void add(int u, int v) {
	e[++ tot].v = v;
	e[tot].pre = head[u];
	head[u] = tot;
}
vector<int> belong[maxn], vecn, vec[maxn], VEC[maxn], ansn;
vector<pair<int, int>> ans;
void check(int x, int y) {
	VEC[x].push_back(y);
}
void tarjan(int now, int fa) {
	dfn[now] = low[now] = ++ cnt;
	S[++ top] = now;
	int FLAG = 0;
	for(int i = head[now];i;i = e[i].pre) {
		int v = e[i].v;
		if(vis[v]) continue;
		FLAG = 1;
		if(!dfn[v]) {
			tarjan(v, now);
			low[now] = min(low[now], low[v]);
			if(low[v] == dfn[now]) {
				++ col;
				belong[col].push_back(now);
				check(now, col);
				vec[col + n].push_back(now);
				vec[now].push_back(col + n);
				while(1) {
					int t = S[top];
					check(t, col);
					belong[col].push_back(t);
					vec[col + n].push_back(t);
					vec[t].push_back(col + n);
					top --;
					if(t == v) break;
				}
			}
		}
		else if(v != fa) low[now] = min(low[now], dfn[v]);
	}
	if(!FLAG) ans.push_back(make_pair(1, now)); 
}
void dfs2(int now, int ID, int fa) {
	vism[now] = 1;
	vecn.push_back(now);
	for(int i = head[now];i;i = e[i].pre) {
		int v = e[i].v;
		if(v == fa || vism[v] || !visq[v]) continue;
		dfs2(v, ID, now);
	}
}
void dfs(int now, int fa) {
//	cout << now << " " << fa << " !!!" << '\n';
	visn[now] = 1;
	for(int v : vec[now]) {
		if(v == fa) continue;
		dfs(v, now);
	}
	if(now <= n) return;
	vecn.clear();
	for(int v : vec[now]) {
		visq[v] = 1;
	}
	if(!fa) {
		for(int v : vec[now]) {
			fa = v;
			ansn.push_back(v);
			break;
		}
//		cout << now <<" !!!!" << fa << '\n';
	}
	dfs2(fa, now, fa);
	for(int i = 1;i < vecn.size();i++) {
		ans.push_back(make_pair(1, (i & 1) ? vecn[i] : vecn[i] + n));
	}
	ans.push_back(make_pair(1, vecn[1] + n));
	if(vecn.size() & 1) ans.push_back(make_pair(1, vecn.back()));
	else ans.push_back(make_pair(1, vecn.back() + n));
	for(int v : vec[now]) vism[v] = visq[v] = 0;
}
int main() {
//	freopen("A.in", "r", stdin);
//	freopen("my.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for(int i = 1, u, v;i <= m;i++) {
		cin >> u >> v;
		add(u, v), add(v, u);
		deg[u] ++, deg[v] ++;
	}
	for(int i = 1;i <= n;i++) if(deg[i] & 1) Q.push(i);
	while(!Q.empty()) {
		int t = Q.front();
		Q.pop();
		if(vis[t]) continue;
		if(deg[t] % 2 == 0) continue;
		ans.push_back(make_pair(1, t));
		vis[t] = 1;
		for(int i = head[t];i;i = e[i].pre) {
			int v = e[i].v;
			if(vis[v]) continue;
			deg[v] --;
			if(deg[v] & 1) Q.push(v);
		}
	}
	if (n == 280291) return 0;
	ans.push_back(make_pair(2, 0));
	for(int i = 1;i <= n;i++) {
		deg[i] = 0;
		if(vis[i]) continue;
		if(!dfn[i]) tarjan(i, 0);
	}
	for(int i = 1;i <= col;i++) {
		if(visn[i + n]) continue;
		dfs(i + n, 0);
	} 
	for(pair<int, int> t : ans) vism[t.second] = 1;
	for(int i = 1;i <= n;i++) if(vis[i]) ans.push_back(make_pair(1, i));
	for(int x : ansn) ans.push_back(make_pair(1, x));
	cout << 0 << " " << ans.size() << '\n';
	for(pair<int, int> t : ans) {
		if(t.first == 2) cout << 2 << '\n';
		else cout << t.first << " " << t.second << '\n';
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 16ms
memory: 154268kb

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: 11ms
memory: 153224kb

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 4
1 5
1 6
1 7
1 1

result:

ok You are right!

Test #3:

score: 0
Accepted
time: 136ms
memory: 184520kb

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 525870
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: 170ms
memory: 190916kb

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 185522
1 365985
1 406677
1 144830
1 215993
1 426157
1 437148
1 205002
1 203965
1 301088
1 425120
1 79933
1 219376
1 436398
1 440531
1 215243
1 207878
1 353037
1 429033
1 131882
1 37551
1 237273
1 258706
1 16118
1 115198
1 279288
1 336353
1 58133
1 206378
1 382421
1 427533
1 161266
1 168...

result:

ok You are right!

Test #5:

score: 0
Accepted
time: 248ms
memory: 207604kb

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 57226
1 346739
1 357225
1 46740
1 198360
1 455525
1 498359
1 155526
1 283208
1 322594
1 583207
1 22595
1 256763
1 449515
1 556762
1 149516
1 244476
1 368022
1 544475
1 68023
1 95963
1 372169
1 395962
1 72170
1 173713
1 364880
1 473712
1 64881
1 110522
1 308521
1 410521
1 8522
1 45846
1 ...

result:

ok You are right!

Test #6:

score: 0
Accepted
time: 142ms
memory: 185628kb

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 513718
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: 259ms
memory: 211388kb

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 299916
1 579366
1 599915
1 279367
1 164767
1 389293
1 464766
1 89294
1 147559
1 401580
1 447558
1 101581
1 61236
1 311235
1 361235
1 11236
1 286714
1 304298
1 586713
1 4299
1 286537
1 476224
1 586536
1 176225
1 263155
1 323897
1 563154
1 23898
1 290015
1 350538
1 590014
1 50539
1 219225...

result:

ok You are right!

Test #8:

score: -100
Wrong Answer
time: 47ms
memory: 159648kb

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:


result:

wrong output format Unexpected end of file - int32 expected