QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#208512#6421. Degree of Spanning TreersjWA 1ms9876kbC++141.8kb2023-10-09 18:12:382023-10-09 18:12:38

Judging History

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

  • [2023-10-09 18:12:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9876kb
  • [2023-10-09 18:12:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+15;
int in[N];
struct edge {
	int to;
	edge *nex;
}*head[N];
int vis[N];
int f[N];
vector<pair<int,int>> e;
vector<pair<int,int>> d;
int find(int x) {
	if(f[x]==x) return x;
	return f[x]=find(f[x]);
}
void uni(int x,int y) {
	if(vis[find(x)]) swap(x,y);
	f[find(x)]=find(y);
}
bool check(int x,int y) {
	return find(x)==find(y);
}
void add(int u,int v) {
	edge *cur=new edge;
	cur->to=v;
	cur->nex=head[u];
	head[u]=cur;
}
int cnt=0;
void get() {
	e.clear();
	d.clear();
	int n,m,u,v,i,j;
	cnt++;
	
	cin>>n>>m; if(cnt==19) {
		cout<<n<<" "<<m<<endl; 
	}
	for(i=1;i<=n;i++) in[i]=vis[i]=0,head[i]=0,f[i]=i;
	for(i=1;i<=m;i++) {
		cin>>u>>v; if(cnt==19) {
		cout<<u<<" "<<v<<endl; 
	}
		if(!check(u,v)) {
			uni(u,v);
			in[u]++;
			in[v]++;
			add(u,v);
			add(v,u);
			d.emplace_back(u,v);
		} else {
			e.emplace_back(u,v);
		}
	}
	return ;
	int r=0;
	for(i=1;i<=n;i++) if(in[i]>n/2) r=i;
	if(!r) {
		cout<<"Yes\n";
		for(auto x:d) {
			tie(u,v)=x;
			cout<<u<<" "<<v<<endl;
		}
		return ;
	}
	for(i=1;i<=n;i++) f[i]=i;
	for(auto x:d) {
		tie(u,v)=x;
		if(u==r) vis[v]=1;
		if(v==r) vis[u]=1;
	}
	for(auto x:e) {
		tie(u,v)=x;
		if(u!=r&&v!=r) {
			if(in[u]+1>n/2) continue;
			if(in[v]+1>n/2) continue;
			in[u]++,in[v]++;
			i=find(u),j=find(v);
			if(in[i]<in[j]) swap(i,j);
			in[i]--,in[r]--;
			vis[i]=0;
			d.emplace_back(u,v);
		}
	}
	if(in[r]>n/2) {
		cout<<"No\n";
	} else {
		cout<<"Yes\n";
		for(auto x:d) {
			tie(u,v)=x;
			if(u==r||v==r) continue;
			cout<<u<<" "<<v<<endl;
		}
		for(i=1;i<=n;i++) if(vis[i]) cout<<r<<" "<<i<<endl;
		return ;
	}
}
int main() {
	//freopen("1.in","r",stdin);
	int T; cin>>T;
	while(T--) get();
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 9876kb

input:

2
6 9
1 2
1 3
1 4
2 3
2 4
3 4
4 5
4 6
4 6
3 4
1 3
2 3
3 3
1 2

output:


result:

wrong answer Line "" doesn't correspond to pattern "Yes|No"