QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#328086#1844. CactusJryno1WA 16ms144452kbC++142.3kb2024-02-15 16:59:172024-02-15 16:59:17

Judging History

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

  • [2024-02-15 16:59:17]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:144452kb
  • [2024-02-15 16:59:17]
  • 提交

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);
	}
	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;
		if(nd[V]==0)S=0;
		else for(int i=0;i<lp[V].size();i++)if(siz[lp[V][i]]>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;	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 16ms
memory: 144452kb

input:

3 3
1 2
1 3
2 3

output:

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

result:

wrong answer Integer parameter [name=m'] equals to 1, violates the range [0, 0]