Submission #1355498
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int n, x, y, rp[100010], rd[100010], bp[100010], bd[100010], ans; vector<int> re[100010], be[100010]; void T_T(){ puts("-1"); exit(0); } void f(int t, int x, int pr, int de, int *p, int *d){ d[x] = de; p[x] = pr; if(t){ for(auto &i : be[x]){ if(i != pr) f(t, i, x, de + 1, p, d); } } else{ for(auto &i : re[x]){ if(i != pr && i != y) f(t, i, x, de + 1, p, d); } } } int main(){ scanf("%d%d%d", &n, &x, &y); auto in = [](int t){ for(int i = 0, x, y; i < n - 1; i++){ scanf("%d%d", &x, &y); (t ? be[x] : re[x]).push_back(y); (t ? be[y] : re[y]).push_back(x); } }; in(0); in(1); f(1, y, 0, 0, bp, bd); fill(rd + 1, rd + n + 1, inf); f(0, x, 0, 0, rp, rd); for(int i = 1; i <= n; i++){ for(auto &j : re[i]){ int a = i, b = j; if(bd[a] > bd[b]) swap(a, b); if(bp[b] == a || bp[bp[b]] == a || bp[a] == bp[b]) continue; if(bd[a] >= rd[a] || bd[b] >= rd[b]) T_T(); } } for(int i = 1; i <= n; i++) if(rd[i] < inf) ans = max(ans, 2 * bd[i]); printf("%d\n", ans); }
Submission Info
Submission Time | |
---|---|
Task | E - Sugigma: The Showdown |
User | kdh9949 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1132 Byte |
Status | RE |
Exec Time | 137 ms |
Memory | 11892 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:26:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d%d", &n, &x, &y); ^ ./Main.cpp: In lambda function: ./Main.cpp:29:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &x, &y); ^
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1400 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0, example1, example2, example3, example4 |
All | doublestar0, doublestar1, doublestar2, doublestar3, doublestar4, doublestar5, doublestar6, doublestar7, example0, example1, example2, example3, example4, giri0, giri1, giri2, giri3, giri4, giri5, giri6, giri7, giri8, giri9, maxrand0, maxrand1, maxrand2, maxrand3, maxrand4, maxrand5, maxrand6, maxrand7, maxrand8, maxrand9, narashi0, narashi1, narashi2, narashi3, narashi4, narashi5, narashi6, narashi7, narashi8, narashi9, ok0, ok1, ok2, ok3, ok4, ok5, ok6, ok7, ok8, ok9, ouh0, ouh1, ouh2, ouh3, ouh4, ouh5, ouh6, ouh7, ouh8, ouh9, same0, same1, same2, same3, same4, same5, same6, same7, same8, same9, sameline0, sameline1, sameline2, sameline3, sameline4, sameline5, sameline6, sameline7, sameline8, sameline9, star0, star1, star2, star3, star4, star5, star6, star7, star8, star9, supersmall0, supersmall1, supersmall2, supersmall3, supersmall4, supersmall5, supersmall6, supersmall7, supersmall8, supersmall9 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
doublestar0 | RE | 102 ms | 6400 KB |
doublestar1 | RE | 98 ms | 6400 KB |
doublestar2 | RE | 99 ms | 6400 KB |
doublestar3 | RE | 105 ms | 6400 KB |
doublestar4 | RE | 98 ms | 6400 KB |
doublestar5 | RE | 100 ms | 6400 KB |
doublestar6 | RE | 102 ms | 6400 KB |
doublestar7 | RE | 100 ms | 6400 KB |
example0 | AC | 3 ms | 6400 KB |
example1 | AC | 3 ms | 6400 KB |
example2 | AC | 3 ms | 6400 KB |
example3 | AC | 3 ms | 6400 KB |
example4 | AC | 3 ms | 6400 KB |
giri0 | RE | 100 ms | 6400 KB |
giri1 | RE | 100 ms | 6400 KB |
giri2 | RE | 99 ms | 6400 KB |
giri3 | RE | 98 ms | 6400 KB |
giri4 | RE | 101 ms | 6400 KB |
giri5 | RE | 99 ms | 6400 KB |
giri6 | RE | 98 ms | 6400 KB |
giri7 | RE | 100 ms | 6400 KB |
giri8 | RE | 100 ms | 6400 KB |
giri9 | RE | 100 ms | 6400 KB |
maxrand0 | RE | 99 ms | 6400 KB |
maxrand1 | RE | 100 ms | 6400 KB |
maxrand2 | RE | 99 ms | 6400 KB |
maxrand3 | RE | 99 ms | 6400 KB |
maxrand4 | RE | 101 ms | 6400 KB |
maxrand5 | RE | 100 ms | 6400 KB |
maxrand6 | RE | 99 ms | 6400 KB |
maxrand7 | RE | 99 ms | 6400 KB |
maxrand8 | RE | 100 ms | 6400 KB |
maxrand9 | RE | 100 ms | 6400 KB |
narashi0 | RE | 100 ms | 6400 KB |
narashi1 | RE | 100 ms | 6400 KB |
narashi2 | RE | 99 ms | 6400 KB |
narashi3 | RE | 99 ms | 6400 KB |
narashi4 | RE | 99 ms | 6400 KB |
narashi5 | RE | 100 ms | 6400 KB |
narashi6 | RE | 99 ms | 6400 KB |
narashi7 | RE | 100 ms | 6400 KB |
narashi8 | RE | 100 ms | 6400 KB |
narashi9 | RE | 98 ms | 6400 KB |
ok0 | RE | 99 ms | 6400 KB |
ok1 | RE | 99 ms | 6400 KB |
ok2 | RE | 99 ms | 6400 KB |
ok3 | RE | 99 ms | 6400 KB |
ok4 | RE | 99 ms | 6400 KB |
ok5 | RE | 101 ms | 6400 KB |
ok6 | RE | 104 ms | 6400 KB |
ok7 | RE | 100 ms | 6400 KB |
ok8 | RE | 100 ms | 6400 KB |
ok9 | RE | 98 ms | 6400 KB |
ouh0 | RE | 98 ms | 6400 KB |
ouh1 | RE | 99 ms | 6400 KB |
ouh2 | RE | 99 ms | 6400 KB |
ouh3 | RE | 99 ms | 6400 KB |
ouh4 | RE | 99 ms | 6400 KB |
ouh5 | RE | 101 ms | 6400 KB |
ouh6 | RE | 100 ms | 6400 KB |
ouh7 | RE | 100 ms | 6400 KB |
ouh8 | RE | 100 ms | 6400 KB |
ouh9 | RE | 99 ms | 6400 KB |
same0 | RE | 101 ms | 6400 KB |
same1 | RE | 100 ms | 6400 KB |
same2 | RE | 98 ms | 6400 KB |
same3 | RE | 98 ms | 6400 KB |
same4 | RE | 99 ms | 6400 KB |
same5 | RE | 101 ms | 6400 KB |
same6 | RE | 100 ms | 6400 KB |
same7 | RE | 100 ms | 6400 KB |
same8 | RE | 98 ms | 6400 KB |
same9 | RE | 97 ms | 6400 KB |
sameline0 | RE | 98 ms | 6400 KB |
sameline1 | RE | 98 ms | 6400 KB |
sameline2 | RE | 99 ms | 6400 KB |
sameline3 | RE | 99 ms | 6400 KB |
sameline4 | RE | 100 ms | 6400 KB |
sameline5 | RE | 99 ms | 6400 KB |
sameline6 | RE | 99 ms | 6400 KB |
sameline7 | RE | 99 ms | 6400 KB |
sameline8 | RE | 99 ms | 6400 KB |
sameline9 | RE | 99 ms | 6400 KB |
star0 | RE | 137 ms | 11892 KB |
star1 | RE | 132 ms | 11512 KB |
star2 | RE | 134 ms | 11512 KB |
star3 | RE | 120 ms | 9464 KB |
star4 | RE | 134 ms | 11636 KB |
star5 | RE | 111 ms | 8060 KB |
star6 | RE | 100 ms | 6400 KB |
star7 | RE | 116 ms | 9080 KB |
star8 | RE | 103 ms | 7040 KB |
star9 | RE | 135 ms | 11892 KB |
supersmall0 | AC | 3 ms | 6400 KB |
supersmall1 | AC | 3 ms | 6400 KB |
supersmall2 | AC | 3 ms | 6400 KB |
supersmall3 | AC | 3 ms | 6400 KB |
supersmall4 | AC | 3 ms | 6400 KB |
supersmall5 | AC | 3 ms | 6400 KB |
supersmall6 | AC | 3 ms | 6400 KB |
supersmall7 | WA | 3 ms | 6400 KB |
supersmall8 | AC | 3 ms | 6400 KB |
supersmall9 | AC | 3 ms | 6400 KB |