Submission #29522562
Source Code Expand
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> e[200002];
pair<int, int> ans[200002];
inline void DFS(const int pos, const int f)
{
static int cnt = 0;
if (e[pos].size() == 1 && f != 0)
{
ans[pos].first = ans[pos].second = (++cnt);
}
else
{
for (const int i : e[pos])
{
if (i != f)
{
DFS(i, pos);
if (ans[pos].first == 0)
{
ans[pos].first = ans[i].first;
}
ans[pos].second = ans[i].second;
}
}
}
return;
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i < n; ++i)
{
int u, v;
scanf("%d%d", &u, &v);
e[u].emplace_back(v);
e[v].emplace_back(u);
}
DFS(1, 0);
for (int i = 1; i <= n; printf("%d %d\n", ans[i].first, ans[i].second), ++i);
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Ranges on Tree |
| User | LXl491214 |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 802 Byte |
| Status | AC |
| Exec Time | 153 ms |
| Memory | 31216 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:34:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
34 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
./Main.cpp:38:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
38 | scanf("%d%d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, example0.txt, example1.txt, example2.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 8 ms | 7788 KiB |
| 001.txt | AC | 94 ms | 16176 KiB |
| 002.txt | AC | 91 ms | 16240 KiB |
| 003.txt | AC | 148 ms | 31216 KiB |
| 004.txt | AC | 153 ms | 23456 KiB |
| 005.txt | AC | 126 ms | 15552 KiB |
| 006.txt | AC | 142 ms | 23444 KiB |
| 007.txt | AC | 142 ms | 19548 KiB |
| 008.txt | AC | 121 ms | 23400 KiB |
| 009.txt | AC | 106 ms | 16584 KiB |
| 010.txt | AC | 46 ms | 10792 KiB |
| 011.txt | AC | 95 ms | 14084 KiB |
| 012.txt | AC | 13 ms | 7952 KiB |
| 013.txt | AC | 25 ms | 9044 KiB |
| 014.txt | AC | 47 ms | 10576 KiB |
| 015.txt | AC | 45 ms | 10312 KiB |
| 016.txt | AC | 21 ms | 8788 KiB |
| 017.txt | AC | 25 ms | 9160 KiB |
| 018.txt | AC | 55 ms | 11488 KiB |
| 019.txt | AC | 78 ms | 13068 KiB |
| 020.txt | AC | 129 ms | 15852 KiB |
| 021.txt | AC | 135 ms | 15852 KiB |
| 022.txt | AC | 143 ms | 15852 KiB |
| 023.txt | AC | 127 ms | 15852 KiB |
| 024.txt | AC | 138 ms | 15856 KiB |
| 025.txt | AC | 137 ms | 15772 KiB |
| 026.txt | AC | 131 ms | 15860 KiB |
| 027.txt | AC | 142 ms | 15764 KiB |
| 028.txt | AC | 125 ms | 15772 KiB |
| 029.txt | AC | 133 ms | 15800 KiB |
| example0.txt | AC | 10 ms | 7824 KiB |
| example1.txt | AC | 9 ms | 7880 KiB |
| example2.txt | AC | 11 ms | 7836 KiB |