QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#327687#1844. CactusfangzichangWA 213ms87536kbC++172.9kb2024-02-15 12:02:152024-02-15 12:02:16

Judging History

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

  • [2024-02-15 12:02:16]
  • 评测
  • 测评结果:WA
  • 用时:213ms
  • 内存:87536kb
  • [2024-02-15 12:02:15]
  • 提交

answer

#include<bits/extc++.h>
#include<bits/stdc++.h>
//#pragma GCC optimize(2)
//本代码含有小众情感元素,建议满 18 周岁后观看
#ifdef __unix__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#else
#define getchar _getchar_nolock
#define putchar _putchar_nolock
#endif
#define debug fprintf(stderr,"Tomoyo after ~It's a wonderful life!~\n")
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define Inf (int)INFINITY
#define inf 0x3f3f3f3f
#define pb push_back
#define ll long long
#define endl '\n'
#define y second
#define x first
using namespace std;
const int N=6e5+10;
void read(){};
template<class T1,class ...T2>
inline void read(T1& ret,T2&... rest){
	ret=0;char c=getchar();bool f=false;
	while(c<'0'||c>'9')f=c=='-',c=getchar();
	while(c>='0'&&c<='9')ret=ret*10+c-'0',c=getchar();
	f&&(ret=-ret),read(rest...);
}
#define cin(...) read(__VA_ARGS__)
template<class T>
inline void print(T x){
	static int s[35],t=0;
	bool f=x<0;if(f)x=-x;
	do s[t++]=x%10,x/=10;while(x);
	f&&putchar('-');while(t)putchar(s[--t]+'0');
}
set<int>nxt[N];
vector<pii>ans;
vector<int>stk,rt,t[N];
int n,m,flg,tot,cnt,dfn[N],low[N],r[N];
#define op(x) ans.pb({1,x})
void work(int u){
	if(!(nxt[u].size()&1))return;
	vector<int>tmp;
	for(int v:nxt[u])tmp.pb(v),nxt[v].erase(u);
	op(u),nxt[u].clear();
	for(int v:tmp)work(v);
}
void Tarjan(int u,int fa){
	low[u]=dfn[u]=++tot,stk.pb(u);
	for(int v:nxt[u])if(v^fa){
		if(!dfn[v]){
			Tarjan(v,u),low[u]=min(low[u],low[v]);
			if(low[v]==dfn[u]){
				t[++cnt].pb(u),t[u].pb(cnt);
				while(stk.back()!=u)
					t[cnt].pb(stk.back()),t[stk.back()].pb(cnt),stk.pop_back();
			}
		}
		else low[u]=min(low[u],dfn[v]);
	}
}
void dfs(int u,int fa){
	for(int v:t[u])if(v^fa)dfs(v,u);
	if(u>n){
		if(r[fa]){
			if(t[u].size()&1){
				for(int i=0;i+1<(int)(t[u].size());i++)op(t[u][i]+(i&1)*n);
				op(t[u][0]+n),op(t[u].back()+n),op(t[u].back());
			}
			else for(int i=0;i<(int)(t[u].size());i++)op(t[u][i]+(i&1)*n);
		}
		else{
			if(t[u].size()&1){
				for(int i=1;i<(int)(t[u].size());i++)op(t[u][i]+(!(i&1))*n);
				op(t[u][1]+n),op(t[u].back());
			}
			else{
				for(int i=1;i<(int)(t[u].size());i++)op(t[u][i]+(!(i&1))*n);
				op(t[u][1]+n),op(t[u].back()+n);
			}
		}
	}
}
int main(){
	cin(n,m),cnt=n;
	for(int i=1,u,v;i<=m;i++)
		cin(u,v),nxt[u].insert(v),nxt[v].insert(u);
	for(int u=1;u<=n;u++)work(u);
	for(int u=1;u<=n;u++)if(nxt[u].size())flg=1;
	if(!flg){
		print(0),putchar(' '),print(ans.size()),putchar(endl);
		for(pii p:ans)print(p.x),putchar(' '),print(p.y),putchar(endl);
		return 0;
	}
	ans.pb({2,0});
	for(int u=1;u<=n;u++){
		if(!nxt[u].size())op(u);
		else if(!dfn[u])rt.pb(u),r[u]=1,Tarjan(u,0);
	}
	for(int u:rt)dfs(u,0);
	print(0),putchar(' '),print(ans.size()),putchar(endl);
	for(pii p:ans){
		print(p.x);if(p.y)putchar(' '),print(p.y);
		putchar(endl);
	}
	return 0;
}

詳細信息

Test #1:

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

input:

3 3
1 2
1 3
2 3

output:

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

result:

ok You are right!

Test #2:

score: 0
Accepted
time: 8ms
memory: 45784kb

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: 213ms
memory: 87536kb

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 521419
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.