QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#328061#1844. CactusfansizheRE 6ms21964kbC++231.8kb2024-02-15 16:43:182024-02-15 16:43:18

Judging History

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

  • [2024-02-15 16:43:18]
  • 评测
  • 测评结果:RE
  • 用时:6ms
  • 内存:21964kb
  • [2024-02-15 16:43:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m;
set<int> edge[300005];
vector<int> ans;
vector<int> e1[600005];
int tot;
int dfn[300005],low[300005],cnt;
stack<int> st;
int vis[300005];
void dfs1(int x){
	ans.push_back(x);
	set<int> S;swap(S,edge[x]);
	for(int y:S)edge[y].erase(x);
	for(int y:S)if(edge[y].size()&1)dfs1(y);
}
void addedge(int x,int y){
	e1[x].push_back(y);
	e1[y].push_back(x);
}
void Tarjan(int x){
	dfn[x]=low[x]=++cnt;
	st.push(x);
	for(int y:edge[x])
		if(!dfn[y]){
			Tarjan(y);
			low[x]=min(low[x],low[y]);
			if(low[y]>=dfn[x]){
				tot++;
				int z;
				do{
					z=st.top();st.pop();
					addedge(z,tot);
				}while(z!=y);
				addedge(x,tot);
			}
		}else low[x]=min(low[x],dfn[y]);
}
void dfs2(int x,int f){
	for(int y:e1[x])if(y!=f)dfs2(y,x);
	if(x>n){
		int p=0;
		for(int i=0;i<e1[x].size();i++)if(e1[x][i]==f){p=i;break;}
		int flag=1;
		for(int i=p+1;i<e1[x].size();i++,flag^=1)
			if(flag)ans.push_back(e1[x][i]);
			else ans.push_back(e1[x][i]+n);
		for(int i=0;i<p;i++,flag^=1)
			if(flag)ans.push_back(e1[x][i]);
			else ans.push_back(e1[x][i]+n);
		flag=0;
		for(int i=p+1;i<e1[x].size();i++,flag^=1)
			if(flag)ans.push_back(e1[x][i]),assert(e1[x][i]!=190282);
			else ans.push_back(e1[x][i]+n);
		for(int i=0;i<p;i++,flag^=1)
			if(flag)ans.push_back(e1[x][i]),assert(e1[x][i]!=190282);
			else ans.push_back(e1[x][i]+n);
	}else vis[x]=1;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;scanf("%d%d",&x,&y);
		edge[x].insert(y);
		edge[y].insert(x);
	}
	for(int i=1;i<=n;i++)if(edge[i].size()&1)dfs1(i);
	ans.push_back(0);
	tot=n;
	for(int i=1;i<=n;i++)if(!dfn[i])Tarjan(i);
	for(int i=1;i<=n;i++)if(!vis[i])dfs2(i,0),ans.push_back(i);
	printf("0 %d\n",(int)ans.size());
	for(int x:ans)if(x>0)printf("1 %d\n",x);else puts("2");
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 21964kb

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: 21956kb

input:

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

output:

0 13
1 4
1 2
1 1
1 6
1 3
2
1 1
1 2
1 3
1 4
1 5
1 6
1 7

result:

ok You are right!

Test #3:

score: -100
Runtime Error

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:


result: