QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#327874#1844. CactusczcWA 78ms44748kbC++142.1kb2024-02-15 15:11:502024-02-15 15:11:50

Judging History

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

  • [2024-02-15 15:11:50]
  • 评测
  • 测评结果:WA
  • 用时:78ms
  • 内存:44748kb
  • [2024-02-15 15:11:50]
  • 提交

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],path[N];;
int tot,fl[N];
int r[N],vis[N];
vector<int> op1,op2,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;
			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&&!vis[v])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;
	}

	if(n<30000){


	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(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: 0ms
memory: 31948kb

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

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
Wrong Answer
time: 78ms
memory: 44748kb

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 209054
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 deg of 102092 is not odd.