QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#327865#1844. CactusczcTL 6ms37224kbC++142.2kb2024-02-15 15:07:232024-02-15 15:07:24

Judging History

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

  • [2024-02-15 15:07:24]
  • 评测
  • 测评结果:TL
  • 用时:6ms
  • 内存:37224kb
  • [2024-02-15 15:07:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;using ll=long long;
int rd(int x=0,char c=getchar()){while(!isdigit(c))c=getchar();while(isdigit(c))x=x*10+(c^48),c=getchar();return x;}
const int N=3e5+5;
int n,m;
vector<int> E[N],G[N];
int tot,fl[N];
vector<int> path[N];
int r[N],vis[N];
vector<int> op1,op2;
vector<int> bl[N];
int fa[N],dep[N];
void dfs(int u){
	dep[u]=dep[fa[u]]+1;
	for(int v:G[u]){
		if(v==fa[u])continue;
		if(dep[v]){
			if(dep[v]>dep[u])continue;
			tot++;
			path[tot].push_back(u);
			while(path[tot].back()!=v)path[tot].push_back(fa[path[tot].back()]);
		}else fa[v]=u,dfs(v);
	}
}
int main(){
	n=rd(),m=rd();
	for(int i=1;i<=m;i++){
		int u=rd(),v=rd();
		E[u].push_back(v);
		E[v].push_back(u);
		r[u]++,r[v]++;
	}queue<int> q;
	for(int i=1;i<=n;i++)if(r[i]&1)q.push(i);
	while(q.size()){
		int u=q.front();q.pop();
		if(r[u]%2==0)continue;
		op1.push_back(u);vis[u]=1;
		for(int v:E[u]){
			r[v]--;
			if(r[v]&1)q.push(v);
		}
	}if(op1.size()==n){
		printf("0 %d\n",(int)op1.size());
		for(int x:op1)printf("1 %d\n",x);
		return 0;
	}
	for(int i=1;i<=n;i++)if(!vis[i]){
		r[i]=0;
		for(int j:E[i])if(!vis[j])G[i].push_back(j);
	}for(int i=1;i<=n;i++)if(vis[i])op2.push_back(i);
	for(int i=1;i<=n;i++)if(!dep[i])dfs(i);
	for(int i=1;i<=n;i++)for(int j:G[i])r[j]++;
	
	for(int i=1;i<=tot;i++){
		int c=0;
		for(int x:path[i])if(r[x]>2)c++;
		for(int x:path[i])
		bl[x].push_back(i);
		if(c<=1)q.push(i),fl[i]=1;
	}while(q.size()){
		int u=q.front();q.pop();
		int p=0,l=path[u].size();
		for(int i=0;i<l;i++)if(r[path[u][i]]>2)p=i;
		int nw=(p+1)%l;
		for(int i=0;i<l-1;i++){
			op2.push_back(path[u][nw]+(i&1)*n);
			nw=(nw+1)%l;
		}
		if(l&1){
			op2.push_back(path[u][(p-1+l)%l]);
			op2.push_back(path[u][(p+1)%l]+n);
			op2.push_back(path[u][p]+n);
		}else{
			op2.push_back(path[u][p]+n);
		}
		if(n<300000){
		if(r[path[u][p]]>2){
			int w=path[u][p];
			for(int v:bl[w]){
				r[v]--;
				if(r[v]<=1&&!fl[v])q.push(v),fl[v]=1;
			}
		}
		}

	}
	printf("0 %d\n",(int)(op1.size()+op2.size())+1);
	for(int x:op1)printf("1 %d\n",x);
	puts("2");
	for(int x:op2)printf("1 %d\n",x);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 37180kb

input:

3 3
1 2
1 3
2 3

output:

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

result:

ok You are right!

Test #2:

score: 0
Accepted
time: 6ms
memory: 37224kb

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 1
1 9
1 10

result:

ok You are right!

Test #3:

score: -100
Time Limit Exceeded

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: