/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 320.0 KiB
#2 Wrong Answer 1ms 320.0 KiB

Code

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

void solve(int tc) {
    int n, q;
    cin >> n >> q;
    vector<vector<int>> tr(n + 1);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        tr[u].push_back(v);
        tr[v].push_back(u);
    }

    vector<int> vis(n + 1, 0);
    vector<int> level(n + 1, 0);
    queue<int> qu;
    qu.push(1);
    vis[1] = 1;

    while (!qu.empty()) {
        int now = qu.front();
        qu.pop();
        for (auto &it : tr[now]) {
            if (!vis[it]) {
                qu.push(it);
                vis[it] = 1;
                level[it] = level[now] + 1;
            }
        }
    }

    sort(level.begin() + 1, level.end());
    for (int i = 1; i <= n; i++) {
        int x = upper_bound(level.begin(), level.end(), i) - level.begin();
        cout << x << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int tc;
    cin >> tc;
    for (int i = 1; i <= tc; i++) {
        solve(i);
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1053 Water on Tree
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-08 10:16:53
Judged At
2024-11-11 03:30:32
Judged By
Score
0
Total Time
1ms
Peak Memory
320.0 KiB