Submission #1687177
Source Code Expand
#include<bits/stdc++.h> #define N 200005 using namespace std; int n,u,v,fa[N],fst[N],to[N],nxt[N],l,dep[N],dis[N],Ans,f[N],q[N]; struct T { int x,y; }a[N],b[N]; vector<int>e[N]; void link(int x,int y) { to[++l]=y;nxt[l]=fst[x];fst[x]=l; to[++l]=x;nxt[l]=fst[y];fst[y]=l; } void dfs(int x) { for (int i=fst[x];i;i=nxt[i]) if (to[i]!=fa[x]) { fa[to[i]]=x; dep[to[i]]=dep[x]+1; dfs(to[i]); } } int Gdis(int x,int y) { if (x==y) return 0; if (fa[x]==y||fa[y]==x) return 1; if (fa[x]==fa[y]||fa[fa[x]]==y||fa[fa[y]]==x) return 2; return 3; } int main() { scanf("%d%d%d",&n,&u,&v); //if (u==v){puts("0");,return 0;} for (int i=1;i<n;i++) scanf("%d%d",&a[i].x,&a[i].y); for (int i=1;i<n;i++) { scanf("%d%d",&b[i].x,&b[i].y); link(b[i].x,b[i].y); } dfs(v); for (int i=1;i<n;i++) { int tmp=Gdis(a[i].x,a[i].y); if (tmp==1) { e[a[i].x].push_back(a[i].y); e[a[i].y].push_back(a[i].x); } else if (tmp==2) { if (fa[a[i].x]!=v||fa[a[i].y]!=v) { e[a[i].x].push_back(a[i].y); e[a[i].y].push_back(a[i].x); } } else f[a[i].x]=f[a[i].y]=1; } memset(dis,0x3f,sizeof dis); int l=0,r=1; q[1]=u;dis[u]=0; while(l<r) { int t=q[++l]; //cout<<t<<' '<<dis[t]<<endl; if (f[t]==1){puts("-1");return 0;} else Ans=max(Ans,dep[t]*2); for (int i=0;i<e[t].size();i++) if (dis[e[t][i]]>dis[t]+1&&dis[t]+1<dep[e[t][i]]) { dis[e[t][i]]=dis[t]+1; q[++r]=e[t][i]; } } printf("%d\n",Ans); }
Submission Info
Submission Time | |
---|---|
Task | E - Sugigma: The Showdown |
User | miaom |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1540 Byte |
Status | RE |
Exec Time | 2104 ms |
Memory | 275584 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:34:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d%d",&n,&u,&v); ^ ./Main.cpp:37:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d",&a[i].x,&a[i].y); ^ ./Main.cpp:40:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d",&b[i].x,&b[i].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 | 1315 ms | 11516 KB |
doublestar1 | RE | 169 ms | 11392 KB |
doublestar2 | RE | 173 ms | 13440 KB |
doublestar3 | RE | 375 ms | 275584 KB |
doublestar4 | RE | 175 ms | 11520 KB |
doublestar5 | RE | 173 ms | 11520 KB |
doublestar6 | RE | 172 ms | 11392 KB |
doublestar7 | RE | 170 ms | 11392 KB |
example0 | AC | 6 ms | 12544 KB |
example1 | AC | 6 ms | 12544 KB |
example2 | AC | 6 ms | 12544 KB |
example3 | AC | 6 ms | 12544 KB |
example4 | AC | 6 ms | 12544 KB |
giri0 | RE | 174 ms | 11520 KB |
giri1 | RE | 172 ms | 11392 KB |
giri2 | WA | 112 ms | 19712 KB |
giri3 | RE | 180 ms | 11392 KB |
giri4 | RE | 178 ms | 13568 KB |
giri5 | RE | 179 ms | 11520 KB |
giri6 | RE | 176 ms | 11520 KB |
giri7 | RE | 177 ms | 11520 KB |
giri8 | RE | 175 ms | 11520 KB |
giri9 | RE | 180 ms | 11520 KB |
maxrand0 | RE | 179 ms | 11520 KB |
maxrand1 | RE | 178 ms | 11520 KB |
maxrand2 | RE | 186 ms | 11520 KB |
maxrand3 | RE | 185 ms | 11392 KB |
maxrand4 | WA | 100 ms | 19712 KB |
maxrand5 | RE | 178 ms | 11520 KB |
maxrand6 | RE | 174 ms | 11392 KB |
maxrand7 | RE | 180 ms | 11520 KB |
maxrand8 | RE | 183 ms | 11520 KB |
maxrand9 | RE | 184 ms | 11520 KB |
narashi0 | RE | 179 ms | 11392 KB |
narashi1 | RE | 177 ms | 11392 KB |
narashi2 | RE | 178 ms | 11392 KB |
narashi3 | RE | 175 ms | 11520 KB |
narashi4 | RE | 183 ms | 11520 KB |
narashi5 | RE | 181 ms | 11520 KB |
narashi6 | RE | 182 ms | 11392 KB |
narashi7 | WA | 121 ms | 19968 KB |
narashi8 | RE | 185 ms | 11520 KB |
narashi9 | RE | 184 ms | 13568 KB |
ok0 | RE | 177 ms | 11392 KB |
ok1 | RE | 174 ms | 11520 KB |
ok2 | RE | 173 ms | 11392 KB |
ok3 | RE | 175 ms | 11520 KB |
ok4 | RE | 174 ms | 11392 KB |
ok5 | RE | 175 ms | 11520 KB |
ok6 | RE | 176 ms | 11520 KB |
ok7 | RE | 172 ms | 11392 KB |
ok8 | RE | 175 ms | 11520 KB |
ok9 | RE | 175 ms | 11392 KB |
ouh0 | RE | 174 ms | 11520 KB |
ouh1 | WA | 110 ms | 20224 KB |
ouh2 | WA | 92 ms | 19456 KB |
ouh3 | RE | 173 ms | 11392 KB |
ouh4 | RE | 172 ms | 11392 KB |
ouh5 | RE | 171 ms | 11392 KB |
ouh6 | WA | 96 ms | 19580 KB |
ouh7 | RE | 173 ms | 11392 KB |
ouh8 | RE | 177 ms | 11520 KB |
ouh9 | WA | 102 ms | 19708 KB |
same0 | RE | 176 ms | 11520 KB |
same1 | WA | 106 ms | 19712 KB |
same2 | RE | 175 ms | 11520 KB |
same3 | RE | 177 ms | 11520 KB |
same4 | RE | 174 ms | 11392 KB |
same5 | RE | 175 ms | 11392 KB |
same6 | RE | 174 ms | 11392 KB |
same7 | WA | 104 ms | 19712 KB |
same8 | RE | 172 ms | 11392 KB |
same9 | RE | 175 ms | 11520 KB |
sameline0 | RE | 174 ms | 13568 KB |
sameline1 | WA | 103 ms | 19712 KB |
sameline2 | RE | 177 ms | 11392 KB |
sameline3 | RE | 175 ms | 11520 KB |
sameline4 | RE | 176 ms | 11520 KB |
sameline5 | WA | 105 ms | 19584 KB |
sameline6 | RE | 175 ms | 11392 KB |
sameline7 | RE | 173 ms | 11520 KB |
sameline8 | RE | 180 ms | 13568 KB |
sameline9 | RE | 174 ms | 11520 KB |
star0 | RE | 171 ms | 11392 KB |
star1 | RE | 182 ms | 11392 KB |
star2 | RE | 174 ms | 13440 KB |
star3 | TLE | 2104 ms | 13440 KB |
star4 | WA | 86 ms | 20340 KB |
star5 | RE | 176 ms | 11520 KB |
star6 | RE | 177 ms | 13568 KB |
star7 | RE | 172 ms | 13440 KB |
star8 | RE | 172 ms | 11392 KB |
star9 | RE | 174 ms | 11520 KB |
supersmall0 | AC | 6 ms | 12544 KB |
supersmall1 | AC | 6 ms | 12544 KB |
supersmall2 | AC | 6 ms | 12544 KB |
supersmall3 | AC | 6 ms | 12544 KB |
supersmall4 | AC | 6 ms | 12544 KB |
supersmall5 | AC | 6 ms | 12544 KB |
supersmall6 | AC | 6 ms | 12544 KB |
supersmall7 | AC | 6 ms | 12544 KB |
supersmall8 | AC | 6 ms | 12544 KB |
supersmall9 | AC | 6 ms | 12544 KB |