QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#327897#1844. CactusHBYoutzeWA 242ms85872kbC++143.2kb2024-02-15 15:25:342024-02-15 15:25:34

Judging History

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

  • [2024-02-15 15:25:34]
  • 评测
  • 测评结果:WA
  • 用时:242ms
  • 内存:85872kb
  • [2024-02-15 15:25:34]
  • 提交

answer

#include <bits/stdc++.h>
//#define int long long
//#define mod 1000000007
using namespace std;

int n,m,head[600010],cnt=1,ru[600010],tmp,cz[600010],tot;
int huan[600010],ruh[600010],head2[600010],cnt2,tmp2,zhan[600010],ztop;
bool vis[600010],vis2[600010],vis3[600010],vis4[1000010];
vector<int> h[600010],d[600010];
set<int> hu[600010];
struct edge
{
	int next,to;
}a[1000010],a2[1000010];
void ad(int u,int v)
{
	a[++cnt].to=v;a[cnt].next=head[u];head[u]=cnt;ru[v]++;
	a[++cnt].to=u;a[cnt].next=head[v];head[v]=cnt;ru[u]++;
}
void ad2(int u,int v)
{
	a2[++cnt2].to=v;a2[cnt2].next=head2[u];head2[u]=cnt2;ruh[v]++;
	a2[++cnt2].to=u;a2[cnt2].next=head2[v];head2[v]=cnt2;ruh[u]++;
}
void dfs(int x,int fa)
{
	if(vis2[x])
	{
		int now=ztop;tmp2++;
		h[tmp2].push_back(x);huan[tmp2]++;
		for(auto j:d[x]) ad(tmp2,j);
		d[x].push_back(tmp2);
		while(zhan[now]!=x)
		{
			h[tmp2].push_back(zhan[now]);
			for(auto j:d[zhan[now]])
			{
				ad2(tmp2,j);hu[j].insert(zhan[now]);
			}
			if(!d[zhan[now]].empty()) hu[tmp2].insert(zhan[now]);
			d[zhan[now]].push_back(tmp2);
			now--;huan[tmp2]++;
		}
		return;
	}
	vis2[x]=1;zhan[++ztop]=x;
	for(int i=head[x];i;i=a[i].next)
	{
		int v=a[i].to;
		if(vis[v]||v==fa||vis4[i]||vis4[i^1]) continue;
		dfs(v,x);vis4[i]=1;
	}
	ztop--;
}
signed main()
{
	cin>>n>>m;tmp=n;
	for(int i=1;i<=m;i++)
	{
		int u,v;cin>>u>>v;ad(u,v);
	}
	set<int> echo;cout<<"0 ";
	for(int i=1;i<=n;i++)
	{
		if(ru[i]%2) echo.insert(i);
	}
	while(!echo.empty())
	{
		set<int>::iterator it=echo.begin();
		int now=*it;echo.erase(now);
		cz[++tot]=now;vis[now]=1;tmp--;
		for(int i=head[now];i;i=a[i].next)
		{
			int v=a[i].to;
			if(vis[v]) continue;
			ru[v]--;
			if(ru[v]%2) echo.insert(v);
			else echo.erase(v);
			if(!ru[v])
			{
				tmp--;vis[v]=1;
			}
		}
	}
	queue<int> q;
	if(tmp==0) goto Marshall_Maximizer;
	cz[++tot]=0;
	for(int i=1;i<=n;i++)
	{
		if(!vis[i]&&!vis2[i]) dfs(i,0);
	}
	for(int i=1;i<=tmp2;i++)
	{
		if(ruh[i]==1||!ruh[i]) q.push(i);
	}
	while(!q.empty())
	{
		int u=q.front();q.pop();
		if(vis3[u]) continue;
		int k,fl=0,fl2=0;
		if(ruh[u]) k=*hu[u].begin();
		else k=h[u][0];
		for(auto j:h[u])
		{
			if(j==k)
			{
				fl2=fl;
				if(huan[u]%2==0) fl^=1;
				continue;
			}
			cz[++tot]=j+fl*n;
			fl^=1;
		}
		int lst,nxt;
		for(int i=0;i<h[u].size();i++)
		{
			if(h[u][i]!=k) continue;
			if(i==0) lst=h[u][h[u].size()-1];
			else lst=h[u][i-1];
			if(i==h[u].size()-1) nxt=h[u][0];
			else nxt=h[u][i+1];
			break;
		}
		if(huan[u]%2)
		{
			if(fl2)
			{
				cz[++tot]=lst+n;cz[++tot]=nxt;
			}
			else
			{
				cz[++tot]=lst;cz[++tot]=nxt+n;
			}
		}
		else
		{
			if(fl2)
			{
				cz[++tot]=lst+n;cz[++tot]=nxt+n;
			}
			else
			{
				cz[++tot]=lst;cz[++tot]=nxt;
			}
		}
		vis3[u]=1;
		if(!ruh[u]) cz[++tot]=k;
		for(int i=head2[u];i;i=a2[i].next)
		{
			int v=a2[i].to;
			if(vis3[v]) continue;
			ruh[v]--;
			if(ruh[v]==1||!ruh[v]) q.push(v);
			if(ruh[v]) hu[v].erase(k);
		}
	}
	Marshall_Maximizer:
	cout<<tot<<'\n';
	for(int i=1;i<=tot;i++)
	{
		if(cz[i]==0) cout<<"2\n";
		else cout<<"1 "<<cz[i]<<'\n';
	}
	return 0;
}
/*
10 12
1 2
1 3
2 5
3 4
3 5
4 6
4 7
5 8
6 9
7 3
9 10
10 4
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 67256kb

input:

3 3
1 2
1 3
2 3

output:

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

result:

ok You are right!

Test #2:

score: 0
Accepted
time: 4ms
memory: 69344kb

input:

7 7
1 2
1 3
2 3
2 4
2 5
3 6
3 7

output:

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

result:

ok You are right!

Test #3:

score: -100
Wrong Answer
time: 242ms
memory: 85872kb

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 261016
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 267103 is not odd.