QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#327828#1844. CactusExplodingKonjacTL 2ms5680kbC++206.1kb2024-02-15 14:53:162024-02-15 14:53:16

Judging History

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

  • [2024-02-15 14:53:16]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:5680kb
  • [2024-02-15 14:53:16]
  • 提交

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]--;
	}
	for(int i=1;i<=n;i++) if(!vis[i]) report1(i);
	qout<<"0 "<<ans.size()<<'\n';
	for(auto &s: ans) qout<<s<<'\n';
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3592kb

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: 2ms
memory: 5680kb

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 3
1 9
1 10
1 2
1 1
1 4
1 5
1 6
1 7

result:

ok You are right!

Test #3:

score: -100
Time Limit Exceeded

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:


result: