/* Sample solution to Hyacinth from NWERC'14. * * Algorithm: greedy; pick new colors whenever possible * (N=2 is a special case) * * Author: Per Austrin */ #include #include #include using namespace std; typedef vector vi; vi adj[1<<15]; int col[1<<15][2]; int nc() { return random() % 1000000000; } void assign(int a, int par) { col[a][0] = par == -1 ? nc() : col[par][1]; // col[a][1] = nc(); col[a][1] = adj[a].size() > 1 ? nc() : col[par][0]; for (auto b: adj[a]) if (b != par) assign(b, a); } int main(void) { int n; scanf("%d", &n); for (int i = 0; i < n-1; ++i) { int a, b; scanf("%d%d", &a, &b); adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i < n; ++i) if (adj[i].size() == 1) { assign(i, -1); break; } for (int i = 1; i <= n; ++i) printf("%d %d\n", col[i][0], col[i][1]); return 0; }