QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#780446#6421. Degree of Spanning TreeSymbolizeCompile Error//C++172.1kb2024-11-25 11:01:462024-11-25 11:01:48

Judging History

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

  • [2024-11-25 11:01:48]
  • 评测
  • [2024-11-25 11:01:46]
  • 提交

answer

/*
	Luogu name: Symbolize
	Luogu uid: 672793
*/
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define rep1(i,l,r) for(register int i=l;i<=r;++i)
#define rep2(i,l,r) for(register int i=l;i>=r;--i)
#define rep3(i,x,y,z) for(register int i=x[y];~i;i=z[i])
#define rep4(i,x) for(auto i:x)
#define debug() puts("----------")
const int N=5e5+10;
const int inf=0x3f3f3f3f3f3f3f3f;
using namespace std;
int t,n,m,fa[N],f[N],times[N];
bool vis[N];
vector<pii> G[N];
struct Graph{int u,v;}e[N];
int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return f*x;
}
int find(int x)
{
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}
void dfs(int x,int Fa,int top)
{
	fa[x]=top;
	rep4(to,G[x])
	{
		if(to.first==Fa) continue;
		dfs(to.first,x,top);
	}
	return;
}
void getans()
{
	n=read();
	m=read();
	rep1(i,1,n) 
	{
		G[i].clear();
		fa[i]=i;
		times[i]=0;
	}
	rep1(i,1,m) vis[i]=0;
	rep1(i,1,m)
	{
		e[i].u=read();
		e[i].v=read();
		int x=find(e[i].u),y=find(e[i].v);
		if(x==y) continue;
		G[x].push_back(make_pair(y,i));
		G[y].push_back(make_pair(x,i));
		fa[x]=y;
		vis[i]=1;
		++times[x];
		++times[y];
	}
	int rt=0; 
	rep1(i,1,n) if(times[i]>n/2) rt=i;
	rep4(to,G[rt])
	{
		f[to.x]=to.y;
		dfs(to.x,rt,to.x);
	}
	rep1(i,1,m)
	{
		int x=find(e[i].u),y=find(e[i].v);
		if(x==y||x==rt||y==rt||vis[i]) continue;
		if(times[e[i].u]<times[e[i].v]) swap(u[i].u,e[i].v),swap(x,y);
		if(times[e[i].v]+1>n/2) continue;
		fa[x]=y;
		vis[f[x]]=0;
		vis[i]=1;
		--times[x];
		--times[rt];
		++times[e[i].u];
		++times[e[i].v];
	}
	if(times[rt]>n/2) puts("No");
	else
	{
		puts("Yes");
		rep1(i,1,m) if(vis[i]) cout<<e[i].u<<' '<<e[i].v<<"\n";
	}
	return;
}
signed main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	t=read();
	while(t--) getans();
	return 0;
}
/*
1
3 4
1 3
2 3
3 3
1 2
*/

詳細信息

answer.code: In function ‘void getans()’:
answer.code:57:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   57 |         rep1(i,1,n)
      |              ^
answer.code:10:38: note: in definition of macro ‘rep1’
   10 | #define rep1(i,l,r) for(register int i=l;i<=r;++i)
      |                                      ^
answer.code:63:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   63 |         rep1(i,1,m) vis[i]=0;
      |              ^
answer.code:10:38: note: in definition of macro ‘rep1’
   10 | #define rep1(i,l,r) for(register int i=l;i<=r;++i)
      |                                      ^
answer.code:64:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   64 |         rep1(i,1,m)
      |              ^
answer.code:10:38: note: in definition of macro ‘rep1’
   10 | #define rep1(i,l,r) for(register int i=l;i<=r;++i)
      |                                      ^
answer.code:78:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   78 |         rep1(i,1,n) if(times[i]>n/2) rt=i;
      |              ^
answer.code:10:38: note: in definition of macro ‘rep1’
   10 | #define rep1(i,l,r) for(register int i=l;i<=r;++i)
      |                                      ^
answer.code:84:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   84 |         rep1(i,1,m)
      |              ^
answer.code:10:38: note: in definition of macro ‘rep1’
   10 | #define rep1(i,l,r) for(register int i=l;i<=r;++i)
      |                                      ^
answer.code:88:54: error: ‘u’ was not declared in this scope
   88 |                 if(times[e[i].u]<times[e[i].v]) swap(u[i].u,e[i].v),swap(x,y);
      |                                                      ^
answer.code:102:22: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
  102 |                 rep1(i,1,m) if(vis[i]) cout<<e[i].u<<' '<<e[i].v<<"\n";
      |                      ^
answer.code:10:38: note: in definition of macro ‘rep1’
   10 | #define rep1(i,l,r) for(register int i=l;i<=r;++i)
      |                                      ^