QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202472#6745. Delete the Treereal_sigma_teamWA 1ms3592kbC++231.7kb2023-10-06 04:38:232023-10-06 04:38:23

Judging History

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

  • [2023-10-06 04:38:23]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3592kb
  • [2023-10-06 04:38:23]
  • 提交

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<int> del(n);
    for (int i = 0; i < 10; ++i) {
        ans.push_back({});
        vector<int> c0, c1;
        vector<int> col(n, 0);
        auto dfs = [&](auto dfs, int u, int p) -> void {
            if (del[u] == 0) {
                if (col[u] == 0) c0.push_back(u);
                else c1.push_back(u);
            }
            for (int to = 0; to < n; ++to) {
                if (adj[u][to] && to != p) {
                    col[to] = col[u] ^ (1 ^ del[to]);
                    dfs(dfs, to, u);
                }
            }
        };
        dfs(dfs, rnd() % n, -1);
        if (c0.size() < c1.size()) swap(c0, c1);
        for (auto j : c0) {
            for (auto k : c0) {
                assert(adj[j][k] == 0);
            }
        }
        for (auto j : c0) {
            ans.back().push_back(j);
            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: 3432kb

input:

5
1 2
1 3
1 4
4 5

output:

3
3 2 3 4
1 1
1 5

result:

ok 

Test #2:

score: 0
Accepted
time: 0ms
memory: 3592kb

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:

2
499 277 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...

result:

ok 

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3568kb

input:

500
80 180
80 254
1 180
80 337
180 323
80 248
180 205
80 189
180 480
80 330
180 454
80 498
142 180
80 193
180 346
80 89
180 389
80 125
180 232
80 93
180 228
80 327
180 357
80 417
180 362
80 278
180 316
80 312
163 180
80 310
176 180
80 463
180 210
80 478
180 294
80 185
124 180
80 143
180 339
80 253
1...

output:

3
250 414 3 5 7 8 10 15 18 20 21 23 27 28 32 33 34 35 43 46 48 50 51 53 54 55 56 61 62 63 64 65 68 72 76 77 78 79 83 86 87 88 89 91 93 94 95 96 98 106 109 111 114 118 120 123 125 126 127 128 130 131 135 137 138 139 143 144 146 147 149 150 151 152 154 156 158 159 161 162 164 165 167 168 171 172 174 1...

result:

wrong answer