QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#327823#1844. CactusExplodingKonjacWA 3ms7744kbC++206.0kb2024-02-15 14:51:502024-02-15 14:51:51

Judging History

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

  • [2024-02-15 14:51:51]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7744kb
  • [2024-02-15 14:51:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define OPENIOBUF

namespace FastIO
{

class FastIOBase
{
 protected:
#ifdef OPENIOBUF
	static const int BUFSIZE=1<<16;
	char buf[BUFSIZE+1];
	int buf_p=0;
#endif
	FILE *target;
	FastIOBase(FILE *f): target(f){}
	~FastIOBase()=default;
 public:
#ifdef OPENIOBUF
	virtual void flush()=0;
#endif
};

class FastOutput final: public FastIOBase
{
 public:
	FastOutput(FILE *f=stdout): FastIOBase(f) {}
#ifdef OPENIOBUF
	~FastOutput() { flush(); }
	void flush() { fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
	void put(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
		putc(x,target);
#endif
	}
	FastOutput &operator <<(char x)
	{ return put(x),*this; }
	FastOutput &operator <<(const char *s)
	{ for(;*s;put(*(s++)));return *this; }
	FastOutput &operator <<(const std::string &s)
	{ return (*this)<<s.c_str(); }
	template<typename T>
	std::enable_if_t<std::is_integral<T>::value,FastOutput&> operator <<(T x)
	{
		if(x<0) return put('-'),(*this)<<(-x);
		char stk[std::numeric_limits<T>::digits10+1],*top=stk;
		do *(top++)=x%10+'0',x/=10; while(x);
		while(top!=stk) put(*(--top));
		return *this;
	}
	template<typename ...T>
	void writesp(T &&...x)
	{ std::initializer_list<int>{((*this)<<(x),put(' '),0)...}; }
	template<typename ...T>
	void writeln(T &&...x)
	{ std::initializer_list<int>{((*this)<<(x),put('\n'),0)...}; }
	template<typename Iter>
	std::enable_if_t<std::is_base_of<
		std::forward_iterator_tag,
		typename std::iterator_traits<Iter>::iterator_category>
	::value> writesp(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<' '; }
	template<typename Iter>
	std::enable_if_t<std::is_base_of<
		std::forward_iterator_tag,
		typename std::iterator_traits<Iter>::iterator_category>
	::value> writeln(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;

class FastInput final: public FastIOBase
{
 private:
	bool __eof;
 public:
	FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
	{ buf_p=BUFSIZE; }
	void flush() { buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
	bool eof()const { return buf[buf_p]==EOF; }
#else
	{}
	bool eof()const { return feof(target); }
#endif
	char get()
	{
		if(__eof) return EOF;
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		char ch=buf[buf_p++];
#else
		char ch=getc(target);
#endif
		return ~ch?ch:(__eof=true,EOF);
	}
	void unget(char c)
	{
		__eof=false;
#ifdef OPENIOBUF
		buf[--buf_p]=c;
#else
		ungetc(c,target);
#endif
	}
	explicit operator bool()const { return !__eof; }
	FastInput &operator >>(char &x)
	{ while(isspace(x=get()));return *this; }
	template<typename T>
	std::enable_if_t<std::is_integral<T>::value,FastInput&> operator >>(T &x)
	{
		char ch,sym=0;x=0;
		while(isspace(ch=get()));
		if(__eof) return *this;
		if(ch=='-') sym=1,ch=get();
		for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=get());
		return unget(ch),sym?x=-x:x,*this;
	}
	FastInput &operator >>(char *s)
	{
		while(isspace(*s=get()));
		if(__eof) return *this;
		for(;!isspace(*s) && !__eof;*(++s)=get());
		return unget(*s),*s='\0',*this;
	}
	FastInput &operator >>(std::string &s)
	{
		char str_buf[(1<<8)+1]={0},*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=get()));
		if(__eof) return *this;
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=get()) && !__eof;p++);
			if(p!=buf_end) break;
			s.append(str_buf);
		}
		unget(*p),*p='\0',s.append(str_buf);
		return *this;
	}
	template<typename ...T>
	void read(T &&...x)
	{ std::initializer_list<int>{((*this)>>(x),0)...}; }
	template<typename Iter>
	std::enable_if_t<std::is_base_of<
		std::forward_iterator_tag,
		typename std::iterator_traits<Iter>::iterator_category>
	::value> read(Iter begin,Iter end)
	{ while(begin!=end) (*this)>>*(begin++); }
}qin;

} // namespace FastIO
using FastIO::qin,FastIO::qout;

using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;

#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#define LOG(...) [](auto...){}(__VA_ARGS__)
#else
#define FILEIO(file)
#define LOG(...) fprintf(stderr,__VA_ARGS__)
#endif

constexpr int MAXN=3e5;

int n,m;
vector<int> G[MAXN+5];
vector<string> ans;
inline void report1(int x) { ans.emplace_back("1 "+to_string(x)); }
inline void report2() { ans.emplace_back("2"); }

int tot,top,cnt,deg[MAXN+5],dfn[MAXN+5],low[MAXN+5],stk[MAXN+5];
bool del[MAXN+5],inq[MAXN+5],vis[MAXN+5];
vector<int> ord,p[MAXN+5];
void tarjan(int u)
{
	dfn[u]=low[u]=++tot;
	stk[++top]=u;
	for(auto &v: G[u])
	{
		if(del[v]) continue;
		if(!dfn[v])
		{
			tarjan(v);
			low[u]=min(low[u],low[v]);
			if(low[v]!=dfn[u]) continue;
			ord.push_back(++cnt);
			p[cnt].push_back(u);
			deg[u]++;
			for(int x=0;x!=v;top--)
			{
				x=stk[top];
				p[cnt].push_back(x);
				deg[x]++;
			}
		}
		else low[u]=min(low[u],dfn[v]);
	}
}

int main()
{
	qin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		qin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
		deg[u]++,deg[v]++;
	}
	queue<int> q;
	for(int i=1;i<=n;i++)
		if(deg[i]&1) q.push(i),inq[i]=true;
	while(!q.empty())
	{
		int u=q.front();
		if(deg[u]&1)
		{
			for(auto &v: G[u])
				if(((--deg[v])&1) && !inq[v])
					q.push(v),inq[v]=true;
			del[u]=true;
			report1(u);
		}
		q.pop(),inq[u]=false;
	}
	fill(deg+1,deg+n+1,0);
	for(int i=1;i<=n;i++)
		if(!del[i] && !dfn[i]) tarjan(i);
	report2();
	for(auto &id: ord)
	{
		auto it=find_if(p[id].begin(),p[id].end(),[](int x) {
			return deg[x]>1;
		});
		rotate(p[id].begin(),it,p[id].end());
		int sz=p[id].size();
		for(int i=1;i<sz;i++)
			report1(p[id][i]+((i&1)?0:n)),vis[p[id][i]]=true;
		if(sz&1)
			report1(p[id][1]+n),report1(p[id][sz-1]);
		else
			report1(p[id][1]+n),report1(p[id][sz-1]+n);
		for(auto &u: p[id]) deg[u]--;
	}
	qout<<"0 "<<ans.size()<<'\n';
	for(auto &s: ans) qout<<s<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 7744kb

input:

3 3
1 2
1 3
2 3

output:

0 5
2
1 3
1 5
1 6
1 2

result:

wrong answer The number of remaining edges is not equal to m'.