QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#786471#6421. Degree of Spanning TreePhangWA 243ms18164kbC++142.1kb2024-11-26 21:40:432024-11-26 21:40:48

Judging History

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

  • [2024-11-26 21:40:48]
  • 评测
  • 测评结果:WA
  • 用时:243ms
  • 内存:18164kb
  • [2024-11-26 21:40:43]
  • 提交

answer

#include<bits/stdc++.h>
#define rep1(i, a, b) for(int i = a; i <= b; ++i)
#define rep2(i, a, b) for(int i = a; i >= b; --i)
#define ft first
#define sd second
#define pii pair <int, int>
#define ll long long
#define ld long double
#define pb push_back
const int N = 2e5 + 10;
using namespace std;
int T, tot, ans, d[N], sz[N], pa[N], vis[N], dfn[N], low[N]; pii ed[N];
vector <pii> e[N];
int find(int x) {return x == pa[x] ? x : pa[x] = find(pa[x]);}
void hb(int x, int y, int i) {
    x = find(x); y = find(y);
    if(x == y) return ;
    vis[i] = 1; pa[x] = y; ++ans;
    ++sz[ed[i].ft]; ++sz[ed[i].sd];
}
void dfs(int u, int fa) {
    dfn[u] = low[u] = ++tot;
    for(auto v : e[u]) if(v.ft ^ fa) {
        if(!dfn[v.ft]) {
            dfs(v.ft, u);
            low[u] = min(low[v.ft], low[u]);
        }
        else low[u] = min(dfn[v.ft], low[u]);
    }
    if(low[u] < dfn[u]) return ;
    for(auto v : e[u]) if(v.ft == fa) {
        hb(u, v.ft, v.sd); break;
    }
}
int main() {
    cin >> T;
//    int cnt = 0;
    while(T--) {
        int n, m; cin >> n >> m; ans = 0;
        rep1(i, 1, n) {
            pa[i] = i, d[i] = 0, e[i].clear();
            dfn[i] = low[i] = sz[i] = 0;
        }
        rep1(i, 1, m) {
            int u, v; cin >> u >> v;
            ed[i] = {u, v}; vis[i] = 0;
            e[u].pb({v, i}); e[v].pb({u, i});
            ++d[u]; ++d[v];
        }
//        if(++cnt == 72) {
//            puts("Yes");
//            cout << n << ',' << m << '|';
//            rep1(i, 1, m) {
//                cout << ed[i].ft << ',' << ed[i].sd << '|';
//            } cout << '\n'; continue;
//        }
        dfs(1, 0); int flg = 0;
        rep1(i, 1, n) if(sz[i] > n / 2) flg = 1;
        if(flg) {puts("No"); continue;}
        rep1(i, 1, m) {
            if(vis[i]) continue;
            int u = ed[i].ft, v = ed[i].sd;
            if(max(sz[u], sz[v]) >= n / 2) continue;
            hb(u, v, i);
        }
        if(ans ^ (n - 1)) {puts("No"); continue;}
        puts("Yes");
        rep1(i, 1, m) if(vis[i]) cout << ed[i].ft << ' ' << ed[i].sd << '\n';
    }
    return 0;
}

详细

Test #1:

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

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: 243ms
memory: 18164kb

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
9 6
5 7
6 5
2 3
3 10
9 1
2 8
4 3
6 2
Yes
3 7
3 9
2 8
3 6
5 1
1 8
8 9
4 8
Yes
10 2
2 4
5 11
9 2
7 12
11 3
3 1
4 6
7 11
6 8
4 5
Yes
4 2
4 3
4 8
6 7
6 2
1 4
7 5
Yes
6 5
5 7
5 9
4 3
2 9
2 3
8 7
5 1
Yes
10 2
2 6
3 2
1 9
8 10
4 6
6 1
2 5
1 7
Yes
5 7
5 4
7 1
2 6
6 7
1 3
Yes
12 3
1 13
7 8
8 2
10 6
1 6
1...

result:

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