QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#327889#1844. Cactusxztmax67WA 279ms76788kbC++142.0kb2024-02-15 15:19:572024-02-15 15:19:57

Judging History

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

  • [2024-02-15 15:19:57]
  • 评测
  • 测评结果:WA
  • 用时:279ms
  • 内存:76788kb
  • [2024-02-15 15:19:57]
  • 提交

answer

#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
#define pb push_Back
using namespace std;
const int N=1e6+100;
int n,m;
vector<int>ans,g[N],G[N];
int vis[N],deg[N];
void dfs(int x)
{
	vis[x]=2;ans.push_back(x);deg[x]=0;
	for(auto y:g[x])if(vis[y]!=2)deg[y]^=1;
	for(auto y:g[x])if(vis[y]!=2&&deg[y])dfs(y);
}
int dfn[N],low[N],dfntot,scc;
stack<int>st;
void tarjan(int x)
{
	dfn[x]=low[x]=++dfntot;st.push(x);
	for(auto y:G[x])
	{
		if(!dfn[y])
		{
			tarjan(y);low[x]=min(low[x],low[y]);if(low[y]>=dfn[x])
			{
				scc++;
				while(st.top()!=x){g[scc].push_back(st.top());g[st.top()].push_back(scc);st.pop();};
				g[scc].push_back(x);g[x].push_back(scc);
			}
		}
		else low[x]=min(low[x],dfn[y]);
	}
}
void dfs(int x,int fa)
{
	vis[x]=1;
	for(auto y:g[x])if(y!=fa)dfs(y,x);
//	cout<<x<<" "<<fa<<endl;
	if(x<=n)return;
	int p=0,sz=g[x].size();
	for(int i=0;i<sz;i++)if(g[x][i]==fa)p=i;else vis[g[x][i]]=2;
//	for(auto y:g[x])cout<<y<<' ';cout<<endl;
	for(int i=1;i<sz;i++)
		if(i&1)ans.push_back(g[x][(p+i)%sz]);
		else ans.push_back(g[x][(p+i)%sz]+n);
	if(sz&1)ans.push_back(g[x][(p+1)%sz]+n),ans.push_back(g[x][(p-1+sz)%sz]);
	else ans.push_back(g[x][(p+1)%sz]+n),ans.push_back(g[x][(p-1+sz)%sz]+n);
}
signed main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;scc=n;
	for(int i=1,x,y;i<=m;i++)cin>>x>>y,g[x].push_back(y),g[y].push_back(x),deg[x]^=1,deg[y]^=1;
	for(int i=1;i<=n;i++)if(deg[i])dfs(i);
	for(int x=1;x<=n;x++)for(auto y:g[x])if(vis[x]!=2&&vis[y]!=2)G[x].push_back(y);
	for(int i=1;i<=n;i++)g[i].clear();
	for(int i=1;i<=n;i++)if(G[i].size()&1)puts("SB");
	for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
	memset(vis,0,sizeof(vis));
	int t=ans.size();
	ans.push_back(0);
	for(int i=1;i<=n;i++)if(!vis[i])dfs(i,0);
	for(int i=1;i<=n;i++)if(vis[i]!=2)ans.push_back(i);
	cout<<0<<" "<<ans.size()<<endl;
	for(auto x:ans)if(!x)cout<<2<<endl;else cout<<1<<" "<<x<<endl;
	return 0;
}
/*
6 6
1 2
2 3
3 4
4 5
5 6
6 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 56468kb

input:

3 3
1 2
1 3
2 3

output:

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

result:

ok You are right!

Test #2:

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

input:

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

output:

0 13
1 4
1 2
1 1
1 6
1 3
2
1 1
1 2
1 3
1 4
1 5
1 6
1 7

result:

ok You are right!

Test #3:

score: -100
Wrong Answer
time: 279ms
memory: 76788kb

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 521873
1 3
1 274816
1 273658
1 217572
1 248509
1 231418
1 73094
1 117739
1 11855
1 48428
1 55953
1 121689
1 234392
1 181317
1 238712
1 77369
1 105062
1 6838
1 130659
1 8
1 44304
1 9
1 10
1 18682
1 63155
1 148043
1 194189
1 26612
1 1155
1 31020
1 108936
1 71065
1 77412
1 124995
1 126920
1 53663
1 4...

result:

wrong answer The deg of 453816 is not odd.