QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#328166#1844. CactusJryno1WA 192ms164352kbC++142.8kb2024-02-15 17:48:502024-02-15 17:48:50

Judging History

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

  • [2024-02-15 17:48:50]
  • 评测
  • 测评结果:WA
  • 用时:192ms
  • 内存:164352kb
  • [2024-02-15 17:48:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e6+10;
#define pii pair<int,int> 
#define fi first
#define se second
#define mkp(x,y) make_pair(x,y)
vector<int>ed[maxn],lp[maxn],bel[maxn];
int del[maxn],deg[maxn],n,m,vis[maxn],dfn[maxn],sta[maxn],tp,cdfn;
int clp,nd[maxn],siz[maxn];
void dfs(int x,int pre){
	dfn[x]=++cdfn,sta[++tp]=x;
	for(auto v:ed[x]){
		if(del[v]||v==pre)continue;
		if(!dfn[v])dfs(v,x);
		else if(dfn[v]<dfn[x]){
			clp++;
			for(int i=tp;;i--){//O(m)
				lp[clp].push_back(sta[i]);
				bel[sta[i]].push_back(clp);
				siz[sta[i]]++;
				if(sta[i]==v)break;
			}
		}
	}
	tp--;
}
vector<pii>ans;
int main(){
	cin.tie(0),cout.tie(0),ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		ed[u].push_back(v);
		ed[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);
	while(!Q.empty()){
		int now=Q.front();
		Q.pop();
		if(del[now]||!(deg[now]&1))continue;
		ans.push_back(mkp(1,now));
		del[now]=1;
		for(auto v:ed[now])deg[v]--,Q.push(v);
	}
	for(int i=1;i<=n;i++)deg[i]=0;
	for(int i=1;i<=n;i++){
		for(auto v:ed[i]){
			if(i<v&&!del[i]&&!del[v])deg[i]++,deg[v]++;
		}
	}
	for(int i=1;i<=n;i++)if(!deg[i])del[i]=1;
	/*for(int i=1;i<=n;i++)cout<<i<<" "<<i+n<<"\n";
	for(int i=1;i<=n;i++){
		for(auto v:ed[i]){
			if(i<v&&!del[i]&&!del[v])cout<<i<<" "<<v<<"\n",cout<<i+n<<" "<<v+n<<"\n";
		}
	}*/
	ans.push_back(mkp(2,-1));
	for(int i=1;i<=n;i++)if(del[i])ans.push_back(mkp(1,i));
	for(int i=1;i<=n;i++)if(!del[i]&&!dfn[i])dfs(i,0);
//	cout<<clp<<endl;
	for(int i=1;i<=n;i++){
		if(bel[i].size()>1)for(auto v:bel[i])nd[v]++;
	}
	for(int i=1;i<=clp;i++)if(nd[i]<=1)Q.push(i);
	while(!Q.empty()){
		int V=Q.front();
		Q.pop();
		if(vis[V])continue;
		vis[V]=1;
		int S=-1;
		if(nd[V]==0)S=0;
		else for(int i=0;i<lp[V].size();i++)if(siz[lp[V][i]]>1)assert(S==-1),S=i;
		vector<int>R;
		R.push_back(lp[V][S]);
		for(int i=S+1;i<lp[V].size();i++)R.push_back(lp[V][i]);
		for(int i=0;i<S;i++)R.push_back(lp[V][i]);
		for(int i=1,o=1;i<R.size();i++,o^=1){
			if(o)ans.push_back(mkp(1,R[i]));
			else ans.push_back(mkp(1,R[i]+n));
		}
		if(R.size()>1)ans.push_back(mkp(1,R[1]+n));
		if(R.size()>2){
			if((R.size()-1)&1)ans.push_back(mkp(1,R[R.size()-1]+n));
			else ans.push_back(mkp(1,R[R.size()-1]));
		}
		if(siz[R[0]]==1){
			ans.push_back(mkp(1,R[0]));
		} else {
			siz[R[0]]--;
			if(siz[R[0]]==1){
				for(auto v:bel[R[0]]){
					nd[v]--;
					if(nd[v]<1&&!vis[v])Q.push(v);
				}
			}
		}
	}
	cout<<0<<" "<<ans.size()<<"\n";
	for(auto v:ans){
		if(v.fi==1)cout<<v.fi<<" "<<v.se<<"\n";
		else cout<<v.fi<<"\n";
	}
	return 0;	
}
/*
8 10
1 2
2 4
1 4
3 4
3 5
5 6
3 6
3 7
3 8
7 8
*/

詳細信息

Test #1:

score: 100
Accepted
time: 22ms
memory: 144252kb

input:

3 3
1 2
1 3
2 3

output:

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

result:

ok You are right!

Test #2:

score: 0
Accepted
time: 20ms
memory: 144268kb

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 4
1 5
1 6
1 7
1 2
1 8
1 9
1 1
1 3

result:

ok You are right!

Test #3:

score: -100
Wrong Answer
time: 192ms
memory: 164352kb

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 520025
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:

wrong answer The number of remaining edges is not equal to m'.