QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#784250#8757. 图hotdogsellerWA 184ms13396kbC++142.5kb2024-11-26 14:17:452024-11-26 14:17:46

Judging History

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

  • [2024-11-26 14:17:46]
  • 评测
  • 测评结果:WA
  • 用时:184ms
  • 内存:13396kb
  • [2024-11-26 14:17:45]
  • 提交

answer

#include<bits/stdc++.h>

#define maxn 200008
#define pii pair<int,int>
#define int long long

using namespace std;

inline int read(){
    int lre=0,f=1;
    char c=getchar();
    while(!isdigit(c)){
        if(c=='-'){
            f=-1;
        }
        c=getchar();
    }
    while(isdigit(c)){
        lre=(lre<<3)+(lre<<1)+(c-'0');
        c=getchar();
    }
    return lre*f;
}

inline int f(int a,int b){
	return (a<<32)|b;
} 

int n,m,s,t;
set<int> ga[maxn];
map<int,int> mp;

void add(int u,int v){
	mp[f(u,v)]++;
	ga[u].insert(v);
}

void del(int u,int v){
	mp[f(u,v)]--;
	if(mp[f(u,v)]==0)ga[u].erase(ga[u].find(v));
}

int cnt=0;
map<int,map<int,int> > root;

int f_f(int x,int y){
	if(root[y][x]==0)root[y][x]=x;
	if(root[y][x]!=x){
		root[y][x]=f_f(root[y][x],y);
	}
	return root[y][x];
} 

void merge(int u,int v,int y){
	if(root[y][u]==0)root[y][u]=u;
	if(root[y][v]==0)root[y][v]=v;
	root[y][f_f(u,y)]=f_f(v,y);
}

bool okay=false;
vector<int> v;
bool visited[maxn];

void dfs(int x,int goal){
//	cout<<"x="<<x<<endl;
	v.push_back(x);visited[x]=true;
	if(x==goal){
		printf("%lld ",v.size());
		for(int i:v){
			printf("%lld ",i);
		} 
		putchar('\n');
		okay=true;
	}else{
		set<int>::iterator it;
		for(it=ga[x].begin();it!=ga[x].end();it++){
			int v=*it;
			if(visited[v])continue;
		//	cout<<x<<"->"<<v<<endl;
			dfs(v,goal);
			if(okay){
				del(x,v);del(v,x);
				break;
			}
		}
	}
	v.pop_back();visited[x]=false;
}

void solve(){
	n=read();m=read();
	mp.clear();cnt=0;root.clear(); 
	for(int i=1;i<=n;i++){
		ga[i].clear(); 
	}
	for(int i=1;i<=m;i++){
		int u=read(),v=read();
		add(u,v);add(v,u);
	//	cout<<"fu="<<f_f(u,cnt)<<" fv="<<f_f(v,cnt)<<endl; 
		if(cnt==0||f_f(u,cnt)==f_f(v,cnt)){
		//	cout<<"new!"<<endl; 
			cnt++;merge(u,v,cnt);
		}else{
			int l=1,r=cnt,mid,ind;
			while(l<=r){
				mid=l+r>>1;
				if(f_f(u,mid)==f_f(v,mid)){
					l=mid+1;
				}else{
					ind=mid;
					r=mid-1;
				}
			}
			merge(u,v,ind);
		}
	}
//	cout<<"cnt="<<cnt<<endl; 
	for(int i=1;i<=n;i++){
		if(f_f(i,cnt)!=i){
			s=i;t=f_f(i,cnt);
			break;
		}
	}
	printf("%lld %lld\n",s,t);
	int k=(m+n-2)/(n-1);
//	cout<<"k="<<k<<endl;
	for(int i=1;i<=k;i++){
	//	cout<<"No "<<i<<".";
		okay=false;
		dfs(s,t);
	}
}

/*

3
3 1
1 3

4 7
1 2
2 3
3 4
4 1
1 3
2 4
1 4

5 5
1 2
2 3
3 4
4 5
3 5
*/ 

signed main(){
	
	memset(visited,0,sizeof(visited));
	
	int t=read();
	while(t--){
		solve();
	} 
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 81ms
memory: 13396kb

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:

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 
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 
2 1
2 2 1 
2...

result:

ok Answer correct. (10000 test cases)

Test #2:

score: -100
Wrong Answer
time: 184ms
memory: 13324kb

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:

5 1
2 5 1 
3 5 2 1 
3 5 2 1 
3 5 3 1 
3 5 3 1 
4 3
5 4 1 2 5 3 
3 4 1 3 
4 4 2 1 3 
2 4 3 
2 4 3 
4 2
3 4 1 2 
2 4 2 
2 4 2 
2 4 2 
2 4 2 
4 1
2 4 1 
3 4 2 1 
3 4 2 1 
3 4 2 1 
3 4 3 1 
2 1
3 2 3 1 
4 2 3 4 1 
4 2 3 5 1 
4 2 3 5 1 
4 2 3 5 1 
2 1
2 2 1 
3 2 3 1 
3 2 4 1 
3 2 4 1 
3 2 5 1 
3 5
5 3 1 ...

result:

FAIL Begin in s. (test case 72)