Submission #1688967
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 +10; const int inf = 0x7f7f7f7f; int read(){ int x=0,flag=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')flag=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*flag; } char str[maxn]; int n,cnte; int head[maxn],to[maxn*2],nxt[maxn*2]; int vis[maxn],Max1[maxn],Max2[maxn],dep[maxn],dis[maxn]; int v1[maxn],v2[maxn],siz[maxn]; int low[maxn],height[maxn]; //low height rt //vis isset //Max1 from leaves the deepest //Max2 from leaves the second //dep : depth //dis : deepest depth with chosen nod void AddEdge(int x,int y){ ++cnte;to[cnte]=y;nxt[cnte]=head[x];head[x]=cnte; } int Dfs(int x,int fa){ siz[x]=vis[x]; Max1[x] = Max2[x] = 0; dis[x] = inf; dep[x] = 0; for(int i=head[x];i;i=nxt[i])if(to[i]^fa){ int tmp = Dfs(to[i],x); siz[x] = siz[x] + tmp; if(tmp) dis[x] = min( dep[to[i]]+1, dis[x] ); dep[x] = max( dep[to[i]]+1, dep[x] ); if( Max1[x] == 0 || dep[to[i]] > dep[Max1[x]] ){ Max2[x] = Max1[x]; Max1[x] = to[i]; } else if( Max2[x] == 0 || dep[to[i]] > dep[Max2[x]] )Max2[x] = to[i]; } // printf("x:%d dep:%d Max1:%d Max2:%d\n",x,dep[x],Max1[x],Max2[x]); return siz[x]; } void dfs(int x,int fa,int Lim){ // printf("x:%d Lim:%d\n",x,Lim); int t1=dep[Max1[x]]+1,t2=dep[Max2[x]]+1; if(Max1[x]==0)t1=0; if(Max2[x]==0)t2=0; if(Lim>t1){t2=t1;t1=Lim;} else if(Lim>t2)t2=Lim; // printf("x:%d max1:%d max2:%d\n",x,t1,t2); height[x] = min(t2+1,t1-1) ; if(!vis[x])low[x]=min(dis[x],((siz[1]-siz[x]>0)?Lim:inf)); else low[x]=0; // printf("x:%d dis[x]:%d Lim:%d\n",x,dis[x],Lim); for(int i=head[x];i;i=nxt[i])if(to[i]^fa){ if(to[i] == Max1[x]) dfs(to[i],x,max(Lim,(Max2[x])?dep[Max2[x]]+1:-inf)+1); else dfs(to[i],x,max(Lim,(Max2[x])?dep[Max1[x]]+1:-inf)+1); } } int main(){ //freopen("test.in","r",stdin),freopen("test.out","w",stdout); n=read(); for(int i=1;i<=n-1;i++){ int x,y;x=read();y=read(); AddEdge(x,y);AddEdge(y,x); } scanf("%s",str+1); for(int i=1;i<=n;i++)if(str[i]=='1')vis[i]=1; Dfs(1,0); dfs(1,0,0); int Ans=0; for(int i=1;i<=n;i++){ if(low[i]<=height[i])Ans += height[i] - low[i] + 1; // printf("i:%d low:%d height:%d\n",i,low[i],height[i]); } printf("%d\n",Ans+1); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Black Radius |
User | GlassesQ |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2378 Byte |
Status | WA |
Exec Time | 70 ms |
Memory | 21632 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:84:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s",str+1); ^
Judge Result
Set Name | Sample | Subtask | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1300 | 0 / 600 | ||||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt |
Subtask | 0_01.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 2_00.txt, 2_01.txt, 2_02.txt, 2_03.txt, 2_04.txt, 2_05.txt, 2_06.txt, 2_07.txt, 2_08.txt, 2_09.txt, 2_10.txt, 2_11.txt, 2_12.txt, 2_13.txt, 2_14.txt, 2_15.txt, 2_16.txt, 2_17.txt, 2_18.txt, 2_19.txt, 2_20.txt, 2_21.txt, 2_22.txt, 2_23.txt, 2_24.txt, 2_25.txt, 2_26.txt, 2_27.txt, 2_28.txt, 2_29.txt, 2_30.txt, 2_31.txt, 2_32.txt, 2_33.txt, 2_34.txt, 2_35.txt, 2_36.txt, 2_37.txt, 2_38.txt, 2_39.txt, 2_40.txt, 2_41.txt, 2_42.txt, 2_43.txt, 2_44.txt, 2_45.txt, 2_46.txt, 2_47.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 4 ms | 8448 KB |
0_01.txt | AC | 4 ms | 8448 KB |
0_02.txt | AC | 4 ms | 8448 KB |
1_00.txt | AC | 4 ms | 8448 KB |
1_01.txt | WA | 59 ms | 21632 KB |
1_02.txt | WA | 57 ms | 18304 KB |
1_03.txt | AC | 51 ms | 12160 KB |
1_04.txt | AC | 39 ms | 12160 KB |
1_05.txt | AC | 35 ms | 12160 KB |
1_06.txt | AC | 46 ms | 12160 KB |
1_07.txt | AC | 47 ms | 12160 KB |
1_08.txt | AC | 53 ms | 12928 KB |
1_09.txt | WA | 53 ms | 16896 KB |
1_10.txt | WA | 53 ms | 16256 KB |
1_11.txt | WA | 58 ms | 21632 KB |
1_12.txt | AC | 48 ms | 14336 KB |
1_13.txt | AC | 54 ms | 16512 KB |
1_14.txt | AC | 49 ms | 14080 KB |
1_15.txt | AC | 48 ms | 13184 KB |
1_16.txt | AC | 51 ms | 14720 KB |
1_17.txt | WA | 56 ms | 15872 KB |
1_18.txt | AC | 57 ms | 12160 KB |
1_19.txt | AC | 50 ms | 12160 KB |
1_20.txt | AC | 55 ms | 12288 KB |
1_21.txt | AC | 55 ms | 12800 KB |
1_22.txt | AC | 42 ms | 12160 KB |
1_23.txt | AC | 43 ms | 12160 KB |
1_24.txt | AC | 47 ms | 12800 KB |
1_25.txt | AC | 43 ms | 13696 KB |
1_26.txt | AC | 48 ms | 12032 KB |
1_27.txt | AC | 42 ms | 12160 KB |
1_28.txt | AC | 40 ms | 12416 KB |
1_29.txt | AC | 47 ms | 14336 KB |
2_00.txt | AC | 4 ms | 8448 KB |
2_01.txt | AC | 61 ms | 21248 KB |
2_02.txt | AC | 64 ms | 19840 KB |
2_03.txt | WA | 64 ms | 19328 KB |
2_04.txt | AC | 63 ms | 16768 KB |
2_05.txt | AC | 62 ms | 16896 KB |
2_06.txt | WA | 70 ms | 17664 KB |
2_07.txt | AC | 55 ms | 12160 KB |
2_08.txt | AC | 56 ms | 12160 KB |
2_09.txt | AC | 56 ms | 12160 KB |
2_10.txt | AC | 41 ms | 12160 KB |
2_11.txt | AC | 44 ms | 12160 KB |
2_12.txt | AC | 43 ms | 12160 KB |
2_13.txt | AC | 41 ms | 12160 KB |
2_14.txt | AC | 37 ms | 12160 KB |
2_15.txt | AC | 40 ms | 12160 KB |
2_16.txt | AC | 49 ms | 12160 KB |
2_17.txt | AC | 48 ms | 12160 KB |
2_18.txt | AC | 56 ms | 12160 KB |
2_19.txt | AC | 48 ms | 12160 KB |
2_20.txt | AC | 48 ms | 12160 KB |
2_21.txt | AC | 53 ms | 12160 KB |
2_22.txt | AC | 49 ms | 12800 KB |
2_23.txt | AC | 51 ms | 13312 KB |
2_24.txt | AC | 56 ms | 13184 KB |
2_25.txt | AC | 59 ms | 17280 KB |
2_26.txt | AC | 58 ms | 16256 KB |
2_27.txt | AC | 62 ms | 17152 KB |
2_28.txt | AC | 53 ms | 15872 KB |
2_29.txt | AC | 61 ms | 20096 KB |
2_30.txt | AC | 62 ms | 18816 KB |
2_31.txt | AC | 68 ms | 16000 KB |
2_32.txt | AC | 50 ms | 12416 KB |
2_33.txt | AC | 54 ms | 14208 KB |
2_34.txt | AC | 54 ms | 15616 KB |
2_35.txt | AC | 61 ms | 17920 KB |
2_36.txt | AC | 53 ms | 12160 KB |
2_37.txt | AC | 54 ms | 12160 KB |
2_38.txt | AC | 52 ms | 13056 KB |
2_39.txt | AC | 58 ms | 12288 KB |
2_40.txt | AC | 51 ms | 12160 KB |
2_41.txt | AC | 51 ms | 12160 KB |
2_42.txt | AC | 40 ms | 12160 KB |
2_43.txt | AC | 52 ms | 16640 KB |
2_44.txt | AC | 41 ms | 12160 KB |
2_45.txt | AC | 39 ms | 12160 KB |
2_46.txt | AC | 39 ms | 12288 KB |
2_47.txt | AC | 47 ms | 14848 KB |