QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#601502#5064. DFS Ordergozonite#RE 0ms0kbC++141.3kb2024-09-30 02:14:012024-09-30 02:14:01

Judging History

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

  • [2024-09-30 02:14:01]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-30 02:14:01]
  • 提交

answer

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <deque>
#include <queue>
#include <tuple>
#include <cmath>
#include <cctype>
#include <stack>
#include <cassert>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
using ll = long long;

int n;
vector<int> adj[int(1e5 + 1)];
int depth[100001], subs[100001];

void dfs(int v, int p, int d) {
    depth[v] = d;
    subs[v] = 1;
    for (auto u : adj[v]) {
        if (u == p) continue;
        dfs(u, v, d+1);
        subs[v] += subs[u];
    }
}

int main() {
    freopen("A.in", "r", stdin);
    freopen("A.out", "w", stdout);

    int T; cin >> T;
    while (T--) {
        // cout << "processing: " << T << endl;
        cin >> n;
        for (int i = 0; i < n-1; i++) {
            int a, b; cin >> a >> b;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        dfs(1, -1, 0);
        for (int i = 1; i <= n; i++) {
            cout << depth[i]+1 << " " << n-subs[i]+1 << endl;
        }
        for (int i = 1; i <= n; i++) adj[i].clear();
    }
    
}

詳細信息

Test #1:

score: 0
Dangerous Syscalls

input:

2
4
1 2
2 3
3 4
5
1 2
2 3
2 4
1 5

output:


result: