QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#780605 | #6421. Degree of Spanning Tree | Symbolize | Compile Error | / | / | C++17 | 2.2kb | 2024-11-25 11:48:52 | 2024-11-25 11:48:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
struct node{
int u,v,id;
node(int u=0,int v=0,int id=0):u(u),v(v),id(id){}
}e[maxn];
vector<node>G[maxn];
bool vis[maxn];
int f[maxn],in[maxn],fa[maxn],dep[maxn];
void add(int u,int v,int id){
G[u].push_back(node(u,v,id));
G[v].push_back(node(v,u,id));
}
int findx(int x){
return f[x]==x?x:f[x] = findx(f[x]);
}
void unite(int x,int y){
}
bool same(int x,int y){
return findx(x)==findx(y);
}
void dfs(int u,int pre,int t){
f[u] = t,dep[u] = dep[pre]+1;
for(int i=0;i<G[u].size();i++){
int v = G[u][i].v;
if(v==pre) continue;
dfs(v,u,t);
}
}
void print(int m){
printf("Yes\n");
for(int i=1;i<=m;i++){
if(vis[i]) printf("%d %d\n",e[i].u,e[i].v);
}
}
int main(){
int T;
scanf("%d",&T);
while (T--){
int n,m,rt = 0;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) f[i] = i,G[i].clear(),in[i] = 0;
for(int i=1;i<=m;i++) vis[i] = false;
for(int i=1;i<=m;i++) {
int u,v;
scanf("%d%d",&u,&v);
e[i] = node(u,v,i);
if(x==y) continue;
unite(u,v);
x = findx(u),y = findx(v);
f[x] = y;
vis[i] = true;
in[u]++;
in[v]++;
add(u,v,i);
}
for(int i=1;i<=n;++i) if(in[i]>n/2) rt=i;
if(n==3){
printf("No\n");
continue;
}
dep[rt] = 0,f[rt] = rt;
for(int i=0;i<G[rt].size();i++){
int v = G[rt][i].v;
fa[v] = G[rt][i].id;
dfs(v,rt,v);
}
for(int i=1;i<=m;i++){
if(in[rt]<=n/2) break;
int u = e[i].u,v = e[i].v;
int fu = findx(u),fv = findx(v);
if(fu==fv||u==rt||v==rt) continue;
if(dep[u]<dep[v]) swap(u,v),swap(fu,fv);
if(dep[v]==1&&in[u]>in[v]) swap(u,v),swap(fu,fv);
++in[u],++in[v],--in[rt],--in[fv];
vis[i] = true,vis[fa[fv]] = false;
f[fv] = fu;//!!!!
}
if(in[rt]>n/2) printf("No\n");
else print(m);
}
return 0;
}
Details
answer.code: In function ‘int main()’: answer.code:50:20: error: ‘x’ was not declared in this scope 50 | if(x==y) continue; | ^ answer.code:50:23: error: ‘y’ was not declared in this scope 50 | if(x==y) continue; | ^ answer.code:52:25: error: ‘x’ was not declared in this scope 52 | x = findx(u),y = findx(v); | ^ answer.code:52:38: error: ‘y’ was not declared in this scope 52 | x = findx(u),y = findx(v); | ^ answer.code:40:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 40 | scanf("%d",&T); | ~~~~~^~~~~~~~~ answer.code:43:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 43 | scanf("%d%d",&n,&m); | ~~~~~^~~~~~~~~~~~~~ answer.code:48:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 48 | scanf("%d%d",&u,&v); | ~~~~~^~~~~~~~~~~~~~