QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506721#6421. Degree of Spanning TreeTimeless123WA 122ms3972kbC++171.4kb2024-08-05 20:55:452024-08-05 20:55:45

Judging History

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

  • [2024-08-05 20:55:45]
  • 评测
  • 测评结果:WA
  • 用时:122ms
  • 内存:3972kb
  • [2024-08-05 20:55:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 9;
const int mod = 1e9 + 7;
#define eps 1e-5
#define inf 2e18
int fa[N];
int find(int x) 
{
    return fa[x]=(fa[x]==x?x:find(fa[x]));
}
int n,m;
struct Edge
{
    int x,y,w;
    bool operator < (const Edge &m) const
    {
        if(w!=m.w) return w<m.w;
        if(x!=m.x) return x<m.x;
        return y<m.y; 
    }
};
vector<Edge> g;
int ind[N],rd[N];


void solve()
{
    cin>>n>>m;
    g.clear();
    for(int i=1;i<=n;++i) ind[i] = rd[i] = 0,fa[i] = i;
    for(int i=1;i<=m;++i)
    {
        int x,y;cin>>x>>y;
        if(x==y) continue;
        ind[y]++,ind[x]++;
        g.push_back({x,y,max(ind[y],ind[x])});
    }

    sort(g.begin(),g.end());
    
    vector<pair<int,int> > v;
     for(auto &[x,y,w] : g)
    {
        int fx = find(x),fy = find(y);
        if(fx==fy) continue;
        v.push_back({x,y});
        rd[y]++,rd[x]++;
        fa[fy]=fx;
    }
    
    bool ok=true;
    for(int i=1;i<=n;++i) if(rd[i] > n/2)
    {
        ok=false;
        break;
    }

    if(!ok)
    {
        cout<<"No"<<'\n';
        return ;
    }
    else 
    {
        cout<<"Yes"<<'\n';
        for(auto &[x,y]:v)
            cout<<x<<' '<<y<<'\n';
    }


}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;  cin>>_;
    while (_--) solve();
    return 0;
} 

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3536kb

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:

Yes
1 2
1 3
1 4
4 5
4 6
No

result:

ok 2 cases

Test #2:

score: -100
Wrong Answer
time: 122ms
memory: 3972kb

input:

11140
10 15
9 6
5 7
6 5
2 3
7 5
7 5
3 10
9 7
5 5
9 1
7 5
2 8
7 5
4 3
6 2
9 19
3 7
3 9
2 8
2 8
3 6
5 1
1 8
8 9
8 3
4 8
5 5
3 1
4 3
1 3
8 6
1 3
7 4
4 3
8 8
12 20
10 2
5 5
2 4
3 3
3 3
5 11
9 2
5 5
7 12
11 3
3 3
3 5
5 3
3 1
4 6
7 11
6 8
4 5
6 12
6 5
8 18
4 2
4 3
2 4
2 4
4 3
4 8
2 2
6 7
2 4
6 2
1 4
8 7
4...

output:

Yes
2 3
5 7
9 6
2 8
3 10
6 5
4 3
6 2
9 1
Yes
2 8
3 7
5 1
3 9
1 8
3 6
7 4
8 9
Yes
5 11
7 12
10 2
2 4
3 5
4 6
6 8
6 12
7 11
9 2
3 1
Yes
4 2
6 7
4 3
8 7
3 5
7 5
1 4
Yes
4 3
6 5
2 3
2 9
8 7
9 7
1 2
5 7
Yes
1 9
10 2
2 6
4 6
8 10
1 7
3 2
6 1
2 5
Yes
2 6
5 7
1 3
5 4
7 1
4 6
Yes
1 13
5 4
7 8
10 6
12 3
1 6
8...

result:

wrong answer case 19, participant does not find a solution but the jury does