QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#492931#8757. 图c20150005ML 30ms13500kbC++141.6kb2024-07-26 17:16:482024-07-26 17:16:48

Judging History

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

  • [2024-07-26 17:16:48]
  • 评测
  • 测评结果:ML
  • 用时:30ms
  • 内存:13500kb
  • [2024-07-26 17:16:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;using ll=long long;
int rd(int x=0,char c=getchar()){int f=1;while(!isdigit(c))f=(c^'-'?1:-1),c=getchar();while(isdigit(c))x=x*10+(c^48),c=getchar();return x*f;}
const int N=4e5+5;
int n,m;
int F[N];int getf(int x){return F[x]==x?x:F[x]=getf(F[x]);}
int id(int x,int y){return (x-1)*n+y;}
vector<int> E[N];
vector<int> s;
int fl;
void dfs(int u,int fa,int to){
//	cout<<u<<endl;
	if(fl)return;
	s.push_back(u);
	if(u==to)return fl=1,void();
	for(int v:E[u]){
		if(fl)return;
		if(v^fa)dfs(v,u,to);
	}
	if(fl)return;
	s.pop_back();
}
void solve(){
	n=rd(),m=rd();
	int k=(m-1)/(n-1)+1;
	for(int i=1;i<=k;i++)for(int j=1;j<=n;j++)E[id(i,j)].clear(),F[id(i,j)]=id(i,j);
	for(int i=1;i<=m;i++){
		int u=rd(),v=rd();
		int l=1,r=k,p=1;
		while(l<=r){
			int mid=(l+r)>>1;
			if(getf(id(mid,u))!=getf(id(mid,v)))p=mid,r=mid-1;
			else l=mid+1;
		}
		E[id(p,u)].push_back(id(p,v));
		E[id(p,v)].push_back(id(p,u));
		F[getf(id(p,v))]=getf(id(p,u));
	}
	int u,v;
	for(int i=1;i<=n;i++)if(E[id(k,i)].size()){u=id(k,i),v=E[id(k,i)][0];break;}
//	for(int i=1;i<=k;i++){
//		cout<<i<<" th\n"<<endl;
//		for(int j=1;j<=n;j++)for(int x:E[id(i,j)])cout<<id(i,j)<<" <-> "<<x<<endl;
//		puts("");
//	}
	u=u-id(k,1)+1,v=v-id(k,1)+1;
	printf("%d %d\n",u,v);
	for(int i=1;i<=k;i++){
//		cout<<i<<" th:\n";
		s.clear();fl=0;
		dfs(id(i,u),0,id(i,v));
		printf("%d ",s.size());
		for(int X:s)printf("%d ",X-id(i,1)+1);
		puts("");
	}
}
int main(){
	int t=rd();while(t--)solve();
	return 0;
}
/*
1
4 7
1 2
2 3
3 4
4 1
1 3
2 4
1 4
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 30ms
memory: 13500kb

input:

10000
2 20
1 2
1 2
2 1
1 2
1 2
2 1
1 2
2 1
1 2
1 2
1 2
1 2
2 1
1 2
1 2
2 1
1 2
1 2
1 2
2 1
2 20
2 1
2 1
2 1
2 1
2 1
1 2
1 2
1 2
1 2
2 1
1 2
1 2
2 1
1 2
1 2
2 1
1 2
1 2
2 1
1 2
2 20
1 2
2 1
1 2
1 2
2 1
2 1
1 2
1 2
2 1
2 1
1 2
1 2
1 2
1 2
2 1
1 2
1 2
1 2
2 1
2 1
2 20
1 2
2 1
2 1
1 2
1 2
1 2
2 1
1 2
2 ...

output:

1 2
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
1 2
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
2 1 2 
1 2
2 1 2 
2...

result:

ok Answer correct. (10000 test cases)

Test #2:

score: -100
Memory Limit Exceeded

input:

10000
5 20
2 1
2 5
5 3
3 1
4 5
1 4
4 3
4 5
3 5
5 4
2 3
5 2
3 4
3 5
1 4
4 3
4 2
2 1
1 3
5 1
5 20
4 2
1 3
1 2
4 5
2 4
3 1
5 3
5 1
4 5
4 3
2 4
1 4
4 3
5 2
1 2
3 5
1 5
4 1
3 4
4 3
5 20
1 4
1 3
1 5
5 1
4 5
3 4
4 5
2 3
1 2
2 4
4 5
4 5
2 4
2 5
4 2
4 3
4 2
2 5
2 1
3 1
5 20
2 5
2 3
4 5
4 2
3 4
2 1
5 4
2 5
2 ...

output:


result: