GUO120822 @ 2024-11-23 13:53:28
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int T,n,m,i,x,y,ans;
vector<int> G[N];
bool vis[N];
int p[N];
void dfs(int x)
{
vis[x]=true;
for (int to:G[x])
{
if (!vis[to]) dfs(to);
}
}
void work()
{
ans=0;
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++) G[i].clear();
for (i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
G[x].push_back(y);
G[y].push_back(x);
}
for (i=1;i<=n;i++) vis[i]=false;
for (i=1;i<=n;i++)
{
if (!vis[i])
{
p[++ans]=i;
dfs(i);
}
}
printf("%d\n",ans-1);
for (i=1;i<=ans-1;i++) printf("%d %d\n",p[i],p[i+1]);
}
int main()
{
freopen("destiny.in","r",stdin);
freopen("destiny.out","w",stdout);
scanf("%d",&T);
while (T--) work();
return 0;
}
by Big_Bishop @ 2024-11-23 14:09:29
什么鬼,什么信友队
by HgSO4_QwQ @ 2024-11-23 14:15:47
信友队啥考试