QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202465#6745. Delete the Treereal_sigma_team#WA 46ms3832kbC++231.7kb2023-10-06 04:30:002023-10-06 04:30:00

Judging History

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

  • [2023-10-06 04:30:00]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:3832kb
  • [2023-10-06 04:30:00]
  • 提交

answer

//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<vector<bool>> adj(n, vector<bool>(n));
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        adj[u][v] = adj[v][u] = 1;
    }
    vector<vector<int>> ans;
    vector<bool> del(n);
    for (int i = 0; i < 10; ++i) {
        ans.push_back({});
        vector<int> vert(n);
        iota(all(vert), 0);
        sort(all(vert), [&](int x, int y) {return accumulate(all(adj[x]), 0) > accumulate(all(adj[y]), 0);});
        vector<bool> used = del;
        for (auto j : vert) {
            if (!used[j]) {
                ans.back().push_back(j);
                used[j] = 1;
                vector<int> neighb;
                for (int k = 0; k < n; ++k) {
                    if (!del[k] && adj[j][k]) neighb.push_back(k);
                }
                for (auto x : neighb) {
                    used[x] = 1;
                    for (auto y : neighb) {
                        if (x != y) adj[x][y] = 1;
                    }
                }
            }
        }
        for (auto j : ans.back()) del[j] = 1;
    }
    while (ans.back().empty()) ans.pop_back();
    cout << ans.size() << '\n';
    for (auto i : ans) {
        cout << i.size();
        for (auto j : i) cout << ' ' << j + 1;
        cout << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 2
1 3
1 4
4 5

output:

4
2 1 5
1 4
1 2
1 3

result:

ok 

Test #2:

score: -100
Wrong Answer
time: 46ms
memory: 3832kb

input:

500
183 443
32 443
334 443
254 443
331 443
348 443
54 443
430 443
275 443
410 443
360 443
443 468
140 443
179 443
93 443
327 443
128 443
365 443
122 443
43 443
46 443
399 443
398 443
269 443
130 443
227 443
412 443
61 443
295 443
98 443
30 443
197 443
397 443
95 443
192 443
266 443
48 443
310 443
28...

output:

10
1 443
1 329
1 344
1 343
1 342
1 341
1 340
1 339
1 338
1 337

result:

wrong answer