QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#162671 | #5064. DFS Order | atateerqerce | TL | 355ms | 11624kb | C++14 | 1.4kb | 2023-09-03 15:44:09 | 2023-09-03 15:44:09 |
Judging History
answer
//ts
#include <bits/stdc++.h>
//The quick brown fox jumps over the lazy dog//
using namespace std;
typedef long long ll;
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define ashar(x) setprecision(x)
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define TXT freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int t, n;
int x, y;
int h[100010], sz[100010];
bool mark[100010];
vector<int> edge[100010];
void dfs(int v)
{
mark[v] = 1;
sz[v] = 1;
for(int u: edge[v])
{
if(!mark[u])
{
h[u] = h[v] + 1;
dfs(u);
sz[v] += sz[u];
}
}
}
int main()
{
fast_io
cin >> t;
while(t--)
{
for(int i = 0; i < 100010; i++)
{
h[i] = 0;
sz[i] = 0;
mark[i] = 0;
}
cin >> n;
for(int i = 0; i < n - 1; i++)
{
cin >> x >> y;
x--, y--;
edge[x].pb(y);
edge[y].pb(x);
}
dfs(0);
// cout << t << endl;
// for(int i = 0; i < n; i++)
// {
// cout << "edge " << i <<": ";
// for(int j : edge[i])
// {
// cout << j << " ";
// }
// cout << endl;
// cout << "h " << i <<" : "<< h[i] << " sz: " << sz[i];
// cout << endl;
// }
for(int i = 0; i < n; i++)
{
int x = edge[i].size();
for(int j = 0; j < x; j++)
{
edge[i].ppb();
}
}
for(int i = 0; i < n; i++)
{
cout << h[i] + 1 << " " << n - sz[i] + 1 << endl;
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 6912kb
input:
2 4 1 2 2 3 3 4 5 1 2 2 3 2 4 1 5
output:
1 1 2 2 3 3 4 4 1 1 2 3 3 5 3 5 2 5
result:
ok 18 numbers
Test #2:
score: 0
Accepted
time: 355ms
memory: 11624kb
input:
10 100000 72823 55259 62351 52308 92651 3592 51367 76912 79245 19657 42249 51964 79361 189 27637 93873 81277 28980 74091 19175 36499 5372 4007 43408 80222 240 58323 89130 7186 75148 68314 35801 714 47923 93849 84391 67266 14569 33233 68208 4770 53070 57228 93090 80479 13476 78786 23062 27420 80196 1...
output:
1 1 11 100000 12 100000 17 99998 18 99999 10 99998 10 99999 22 100000 14 100000 10 99995 14 99999 13 99998 10 99981 12 99998 10 99998 12 100000 10 100000 15 100000 17 99999 17 99995 11 100000 19 99997 15 99999 13 99991 8 99999 13 100000 21 99993 11 99993 16 100000 16 100000 12 100000 14 99974 10 999...
result:
ok 2000000 numbers
Test #3:
score: -100
Time Limit Exceeded
input:
1000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...