QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#328174#1844. CactusJryno1RE 15ms147696kbC++142.8kb2024-02-15 17:52:352024-02-15 17:52:36

Judging History

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

  • [2024-02-15 17:52:36]
  • 评测
  • 测评结果:RE
  • 用时:15ms
  • 内存:147696kb
  • [2024-02-15 17:52:35]
  • 提交

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)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);
				}
			}
		}
	}
	for(int i=1;i<=clp;i++)assert(vis[i]==1);
	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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 15ms
memory: 147696kb

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: 12ms
memory: 147404kb

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