QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#86954#4218. Hidden GraphExplodingKonjacRE 3ms3552kbC++175.8kb2023-03-11 15:21:282023-03-11 15:24:36

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-11 15:24:36]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:3552kb
  • [2023-03-11 15:21:28]
  • 提交

answer

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

namespace FastIO
{

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

class FastOutput: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
		{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
 protected:
	inline void __putc(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE)flush();
#else
		putc(x,target);
#endif
	}
	template<typename T>
	inline void __write(T x)
	{
		static char stk[64],*top;top=stk;
		if(x<0) return __putc('-'),__write(-x);
		do *(top++)=x%10,x/=10; while(x);
		for(;top!=stk;__putc(*(--top)+'0'));
	}
 public:
	FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
	inline void setTarget(FILE *f) { this->flush(),target=f; }
	~FastOutput(){ flush(); }
#else
	inline void setTarget(FILE *f) { target=f; }
#endif
	template<typename ...T>
	inline void writesp(const T &...x)
		{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
	template<typename ...T>
	inline void writeln(const T &...x)
		{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
	inline FastOutput &operator <<(char x)
		{ return __putc(x),*this; }
	inline FastOutput &operator <<(const char *s)
		{ for(;*s;__putc(*(s++)));return *this; }
	inline FastOutput &operator <<(const string &s)
		{ return (*this)<<s.c_str(); }
	template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
	inline FastOutput &operator <<(const T &x)
		{ return __write(x),*this; }
}qout;

class FastInput: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
		{ buf[fread(buf,1,BUFSIZE,target)]='\0',buf_p=0; }
#endif
 protected:
	inline char __getc()
	{
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		return buf[buf_p++];
#else
		return getc(target);
#endif
	}
 public:
#ifdef OPENIOBUF
	FastInput(FILE *f=stdin): FastIOBase(f){ buf_p=BUFSIZE; }
	inline void setTarget(FILE *f) { this->flush(),target=f; }
#else
	FastInput(FILE *f=stdin): FastIOBase(f){}
	inline void setTarget(FILE *f) { target=f; }
#endif
	inline char getchar() { return __getc(); }
	template<typename ...T>
	inline void read(T &...x)
		{ initializer_list<int>{(this->operator>>(x),0)...}; }
	inline FastInput &operator >>(char &x)
		{ while(isspace(x=__getc()));return *this; }
	template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
	inline FastInput &operator >>(T &x)
	{
		static char ch,sym;x=sym=0;
		while(isspace(ch=__getc()));
		if(ch=='-') sym=1,ch=__getc();
		for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
		return sym?x=-x:x,*this;
	}
	inline FastInput &operator >>(char *s)
	{
		while(isspace(*s=__getc()));
		for(;!isspace(*s) && *s && ~*s;*(++s)=__getc());
		return *s='\0',*this;
	}
	inline FastInput &operator >>(string &s)
	{
		char str_buf[(1<<8)+1],*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=__getc()));
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=__getc()) && *p && ~*p;p++);
			*p='\0',s.append(str_buf);
			if(p!=buf_end) break;
		}
		return *this;
	}
}qin;

} // namespace FastIO
using namespace FastIO;

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)
#else
#define FILEIO(file)
#endif

int n,m,k,deg[2005],col[2005];
bool vis[2005];
vector<int> p[2005],g[2005],_g[2005];

mt19937 mt_rnd(19260817);//chrono::system_clock::now().time_since_epoch().count());
inline pair<int,int> ask(const vector<int> &p)
{
	int u,v;
	qout<<"? "<<p.size()<<' ';
	for(auto &i: p) qout<<i<<' ';
	qout<<'\n',fflush(stdout);
#ifdef DADALZY
	set<int> s;
	vector<pair<int,int>> vec;
	for(auto &u: p) s.insert(u);
	for(auto &u: p) for(auto &v: _g[u])
	{
		if(!s.count(v)) continue;
		if(u>v) continue;
		vec.emplace_back(u,v);
	}
	if(vec.empty()) u=v=-1;
	else tie(u,v)=vec[mt_rnd()%vec.size()];
	return qout<<u<<' '<<v<<'\n',make_pair(u,v);
#else
	return qin>>u>>v,make_pair(u,v);
#endif
}
inline void answer(const vector<pair<int,int>> &e)
{
	qout<<"! "<<e.size()<<'\n';
	for(auto &[u,v]: e) qout<<u<<' '<<v<<'\n';
	fflush(stdout);
}
int main()
{
	qin>>n;
#ifdef DADALZY
	qin>>m;
	for(int i=1,u,v;i<=m;i++)
	{
		qin>>u>>v;
		_g[u].push_back(v);
		_g[v].push_back(u);
	}
#endif
	k=1,p[1].push_back(1);
	for(int x=2;x<=n;x++)
	{
		for(int j=1;j<=k;j++)
		{
			vector<int> now(move(p[j]));
			now.push_back(x);
			while(now.size()>1)
			{
				auto [u,v]=ask(now);
				if(u==-1 && v==-1) break;
				assert(u==x || v==x);
				g[u].push_back(v);
				g[v].push_back(u);
				now.erase(find(now.begin(),now.end(),u+v-x));
			}
		}
		priority_queue<pair<int,int>,vector<pair<int,int>>,greater<>> q;
		stack<int> ord;
		for(int i=1;i<=x;i++) deg[i]=g[i].size(),vis[i]=false;
		for(int i=1;i<=x;i++) q.emplace(deg[i],i);
		k=0;
		while(!q.empty())
		{
			auto [d,u]=q.top();q.pop();
			if(vis[u]) continue;
			k=max(k,d+1),vis[u]=true,ord.push(u);
			for(auto &v: g[u])
			{
				if((--deg[v])>=k) continue;
				if(vis[v]) continue;
				q.emplace(deg[v],v);
			}
		}
		while(!ord.empty())
		{
			int u=ord.top();ord.pop();
			vector<bool> vis(k+1);
			vis[u]=false,col[u]=1;
			for(auto &v: g[u]) if(!vis[v]) vis[col[v]]=true;
			while(vis[col[u]]) col[u]++;
			p[col[u]].push_back(u);
		}
	}
	vector<pair<int,int>> ans;
	for(int u=1;u<=n;u++)
		for(auto &v: g[u])
			if(u<v) ans.emplace_back(u,v);
	answer(ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3516kb

input:

3
1 2
2 3
1 3

output:

? 2 1 2 
? 2 2 3 
? 2 1 3 
! 3
1 2
1 3
2 3

result:

ok correct

Test #2:

score: 0
Accepted
time: 3ms
memory: 3524kb

input:

10
1 2
-1 -1
1 3
-1 -1
1 4
4 5
2 5
-1 -1
-1 -1
2 6
-1 -1
-1 -1
3 7
-1 -1
-1 -1
3 8
4 8
-1 -1
-1 -1
3 9
-1 -1
-1 -1
3 10
4 10
-1 -1
-1 -1

output:

? 2 1 2 
? 2 2 3 
? 2 1 3 
? 3 3 2 4 
? 2 1 4 
? 4 4 3 2 5 
? 3 3 2 5 
? 2 3 5 
? 2 1 5 
? 4 4 2 3 6 
? 3 4 3 6 
? 3 5 1 6 
? 4 2 4 3 7 
? 3 2 4 7 
? 4 5 1 6 7 
? 4 2 4 3 8 
? 3 2 4 8 
? 2 2 8 
? 5 5 1 7 6 8 
? 4 4 3 2 9 
? 3 4 2 9 
? 6 8 1 5 7 6 9 
? 4 4 3 2 10 
? 3 4 2 10 
? 2 2 10 
? 7 8 1 5 9 7 ...

result:

ok correct

Test #3:

score: 0
Accepted
time: 2ms
memory: 3480kb

input:

5
2 1
3 2
3 1
4 2
-1 -1
4 1
5 2
-1 -1
5 1

output:

? 2 1 2 
? 2 2 3 
? 2 1 3 
? 2 2 4 
? 2 3 4 
? 2 1 4 
? 2 2 5 
? 3 4 3 5 
? 2 1 5 
! 7
1 2
1 3
1 4
1 5
2 3
2 4
2 5

result:

ok correct

Test #4:

score: 0
Accepted
time: 3ms
memory: 3548kb

input:

3
2 1
-1 -1
1 3

output:

? 2 1 2 
? 2 2 3 
? 2 1 3 
! 2
1 2
1 3

result:

ok correct

Test #5:

score: 0
Accepted
time: 2ms
memory: 3552kb

input:

6
1 2
3 2
3 1
4 2
3 4
-1 -1
2 5
3 5
4 5
-1 -1
-1 -1
3 6
-1 -1
-1 -1

output:

? 2 1 2 
? 2 2 3 
? 2 1 3 
? 2 2 4 
? 2 3 4 
? 2 1 4 
? 2 2 5 
? 2 3 5 
? 3 4 1 5 
? 2 1 5 
? 2 2 6 
? 2 3 6 
? 3 4 1 6 
? 2 5 6 
! 9
1 2
1 3
2 3
2 4
2 5
3 4
3 5
3 6
4 5

result:

ok correct

Test #6:

score: -100
Dangerous Syscalls

input:

27
-1 -1
3 1
3 2
-1 -1
-1 -1
1 5
2 5
-1 -1
3 5
6 1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
1 8
-1 -1
6 8
-1 -1
-1 -1
1 9
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
10 8
-1 -1
1 11
4 11
-1 -1
6 11
-1 -1
5 11
-1 -1
-1 -1
-1 -1
5 12
-1 -1
10 13
-1 -1
6 13
-1 -1
5 13
8 13
14 12
14 1
-1 -1
6 14
-1 -1
14 8
14 5

output:

? 2 1 2 
? 3 2 1 3 
? 2 2 3 
? 3 2 1 4 
? 2 3 4 
? 4 2 1 4 5 
? 3 2 4 5 
? 2 4 5 
? 2 3 5 
? 4 2 1 4 6 
? 3 2 4 6 
? 2 3 6 
? 2 5 6 
? 4 1 2 4 7 
? 3 3 6 7 
? 2 5 7 
? 5 1 2 7 4 8 
? 4 2 7 4 8 
? 3 3 6 8 
? 2 3 8 
? 2 5 8 
? 5 1 2 7 4 9 
? 4 2 7 4 9 
? 3 6 3 9 
? 3 8 5 9 
? 5 1 2 7 4 10 
? 4 6 3 9 1...

result: