Submission #1798906
Source Code Expand
#include<set> #include<map> #include<cmath> #include<queue> #include<bitset> #include<string> #include<cstdio> #include<cctype> #include<cassert> #include<cstdlib> #include<cstring> #include<sstream> #include<iostream> #include<algorithm> #define For(i,x,y) for (int i=x;i<y;i++) #define pb push_back #define mp make_pair #define fi first #define se second #define lf else if #define dprintf(...) fprintf(stderr,__VA_ARGS__) using namespace std; typedef long long ll; typedef double db; typedef pair<int,int> pii; typedef vector<int> Vi; int IN(){ int c,f,x; while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0'); while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x; } const int N=200000+19; const int oo=(1<<30)-1; struct Edge{ int y,nxt; } E[N*2]; Vi V[N]; int D[N],U[N],top[N],low[N],A[N],B[N]; int n; char s[N]; ll ans; void Link(int x,int y){ V[x].pb(y); V[y].pb(x); } void dfs(int x,int fa){ int y; A[x]=(s[x]=='1'); For(i,0,V[x].size()) if ((y=V[x][i])!=fa){ dfs(y,x); D[x]=max(D[x],D[y]+1); A[x]|=A[y]; } } void dfs2(int x,int fa){ int mx=U[x],tmp=B[x]|(s[x]=='1'); for (int y:V[x]) if (y!=fa){ B[y]|=tmp; U[y]=max(U[y],mx+1); mx=max(mx,D[y]+1); tmp|=A[y]; } mx=U[x],tmp=B[x]|(s[x]=='1'); for (int i=int(V[x].size())-1,y;~i;i--) if ((y=V[x][i])!=fa){ B[y]|=tmp; U[y]=max(U[y],mx+1); mx=max(mx,D[y]+1); tmp|=A[y]; } for (int y:V[x]) if (y!=fa) dfs2(y,x); } void calc(int x,int fa){ Vi T; top[x]=max(D[x],U[x])-1; low[x]=n; T.pb(-1); if (~fa){ T.pb(U[x]-1); if (B[x]) low[x]=min(low[x],U[x]); } for (int y:V[x]) if (y!=fa){ T.pb(D[y]); if (A[y]) low[x]=min(low[x],D[y]+1); calc(y,x); } sort(T.begin(),T.end(),greater<int>()); top[x]=min(top[x],T[1]+2); } int main(){ n=IN(); For(i,1,n) Link(IN(),IN()); scanf("%s",s+1); if (n==1){ puts("1"); return 0; } dfs(1,-1); dfs2(1,-1); calc(1,-1); For(i,1,n+1) if (s[i]=='1'){ ans+=max(top[i]+1,0); } else{ ans+=max(top[i]-max(low[i],1)+1,0); } ans++; cout<<ans<<endl; }
Submission Info
Submission Time | |
---|---|
Task | F - Black Radius |
User | rxdoi |
Language | C++14 (GCC 5.4.1) |
Score | 1900 |
Code Size | 2155 Byte |
Status | AC |
Exec Time | 168 ms |
Memory | 40576 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:100:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s",s+1); ^
Judge Result
Set Name | Sample | Subtask | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1300 / 1300 | 600 / 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 | 3 ms | 8448 KB |
0_01.txt | AC | 3 ms | 8448 KB |
0_02.txt | AC | 3 ms | 8448 KB |
1_00.txt | AC | 3 ms | 8448 KB |
1_01.txt | AC | 168 ms | 40576 KB |
1_02.txt | AC | 163 ms | 32128 KB |
1_03.txt | AC | 119 ms | 16896 KB |
1_04.txt | AC | 112 ms | 17912 KB |
1_05.txt | AC | 102 ms | 19060 KB |
1_06.txt | AC | 113 ms | 16896 KB |
1_07.txt | AC | 114 ms | 17024 KB |
1_08.txt | AC | 117 ms | 18944 KB |
1_09.txt | AC | 137 ms | 28800 KB |
1_10.txt | AC | 132 ms | 27008 KB |
1_11.txt | AC | 154 ms | 40320 KB |
1_12.txt | AC | 143 ms | 22272 KB |
1_13.txt | AC | 162 ms | 27904 KB |
1_14.txt | AC | 131 ms | 21632 KB |
1_15.txt | AC | 130 ms | 19456 KB |
1_16.txt | AC | 130 ms | 23424 KB |
1_17.txt | AC | 150 ms | 26112 KB |
1_18.txt | AC | 111 ms | 16768 KB |
1_19.txt | AC | 115 ms | 16896 KB |
1_20.txt | AC | 114 ms | 17024 KB |
1_21.txt | AC | 122 ms | 18432 KB |
1_22.txt | AC | 102 ms | 17532 KB |
1_23.txt | AC | 105 ms | 17404 KB |
1_24.txt | AC | 114 ms | 18600 KB |
1_25.txt | AC | 108 ms | 20984 KB |
1_26.txt | AC | 103 ms | 17276 KB |
1_27.txt | AC | 97 ms | 17912 KB |
1_28.txt | AC | 92 ms | 18552 KB |
1_29.txt | AC | 146 ms | 22396 KB |
2_00.txt | AC | 3 ms | 8448 KB |
2_01.txt | AC | 164 ms | 39552 KB |
2_02.txt | AC | 165 ms | 35840 KB |
2_03.txt | AC | 165 ms | 34688 KB |
2_04.txt | AC | 148 ms | 28288 KB |
2_05.txt | AC | 144 ms | 28672 KB |
2_06.txt | AC | 152 ms | 30336 KB |
2_07.txt | AC | 117 ms | 16896 KB |
2_08.txt | AC | 117 ms | 16896 KB |
2_09.txt | AC | 116 ms | 16768 KB |
2_10.txt | AC | 97 ms | 17912 KB |
2_11.txt | AC | 105 ms | 17912 KB |
2_12.txt | AC | 101 ms | 17912 KB |
2_13.txt | AC | 78 ms | 19060 KB |
2_14.txt | AC | 77 ms | 19060 KB |
2_15.txt | AC | 80 ms | 19060 KB |
2_16.txt | AC | 111 ms | 16896 KB |
2_17.txt | AC | 113 ms | 16896 KB |
2_18.txt | AC | 111 ms | 16896 KB |
2_19.txt | AC | 111 ms | 17024 KB |
2_20.txt | AC | 121 ms | 17024 KB |
2_21.txt | AC | 114 ms | 17024 KB |
2_22.txt | AC | 116 ms | 18688 KB |
2_23.txt | AC | 120 ms | 19968 KB |
2_24.txt | AC | 122 ms | 19584 KB |
2_25.txt | AC | 138 ms | 29568 KB |
2_26.txt | AC | 137 ms | 27136 KB |
2_27.txt | AC | 140 ms | 29568 KB |
2_28.txt | AC | 131 ms | 25984 KB |
2_29.txt | AC | 156 ms | 36736 KB |
2_30.txt | AC | 145 ms | 33408 KB |
2_31.txt | AC | 147 ms | 26240 KB |
2_32.txt | AC | 115 ms | 17664 KB |
2_33.txt | AC | 125 ms | 21888 KB |
2_34.txt | AC | 133 ms | 25472 KB |
2_35.txt | AC | 149 ms | 31104 KB |
2_36.txt | AC | 114 ms | 16768 KB |
2_37.txt | AC | 114 ms | 16896 KB |
2_38.txt | AC | 119 ms | 19200 KB |
2_39.txt | AC | 115 ms | 17152 KB |
2_40.txt | AC | 111 ms | 17784 KB |
2_41.txt | AC | 110 ms | 17152 KB |
2_42.txt | AC | 95 ms | 17784 KB |
2_43.txt | AC | 135 ms | 28160 KB |
2_44.txt | AC | 95 ms | 17912 KB |
2_45.txt | AC | 86 ms | 18936 KB |
2_46.txt | AC | 86 ms | 19060 KB |
2_47.txt | AC | 117 ms | 23752 KB |