Submission #1798886
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]; 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; For(i,0,V[x].size()) if ((y=V[x][i])!=fa){ dfs(y,x); D[x]=max(D[x],D[y]+1); } } void dfs2(int x,int fa){ int mx=U[x],y; for (int y:V[x]) if (y!=fa){ U[y]=max(U[y],mx+1); mx=max(mx,D[y]+1); } mx=U[x]; for (int i=int(V[x].size())-1;~i;i--) if ((y=V[x][i])!=fa){ U[y]=max(U[y],mx+1); mx=max(mx,D[y]+1); } 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(0); if (~fa){ T.pb(U[x]-1); low[x]=min(low[x],U[x]); } for (int y:V[x]) if (y!=fa){ T.pb(D[y]); low[x]=min(low[x],D[y]); calc(y,x); } sort(T.begin(),T.end(),greater<int>()); top[x]=min(top[x],T[1]+1); } 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 | 0 |
Code Size | 1989 Byte |
Status | WA |
Exec Time | 183 ms |
Memory | 38528 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:94: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 | 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 | 3 ms | 6400 KB |
0_01.txt | AC | 3 ms | 6400 KB |
0_02.txt | AC | 3 ms | 6400 KB |
1_00.txt | AC | 3 ms | 6400 KB |
1_01.txt | WA | 183 ms | 38528 KB |
1_02.txt | WA | 162 ms | 30080 KB |
1_03.txt | WA | 146 ms | 14848 KB |
1_04.txt | WA | 103 ms | 15864 KB |
1_05.txt | AC | 73 ms | 17012 KB |
1_06.txt | WA | 116 ms | 14848 KB |
1_07.txt | WA | 105 ms | 14976 KB |
1_08.txt | WA | 120 ms | 16896 KB |
1_09.txt | WA | 137 ms | 26752 KB |
1_10.txt | WA | 149 ms | 24960 KB |
1_11.txt | WA | 153 ms | 38272 KB |
1_12.txt | WA | 121 ms | 20352 KB |
1_13.txt | WA | 131 ms | 25856 KB |
1_14.txt | WA | 138 ms | 19584 KB |
1_15.txt | WA | 132 ms | 17408 KB |
1_16.txt | WA | 158 ms | 21376 KB |
1_17.txt | WA | 156 ms | 24064 KB |
1_18.txt | WA | 121 ms | 14720 KB |
1_19.txt | WA | 118 ms | 14848 KB |
1_20.txt | WA | 118 ms | 14976 KB |
1_21.txt | WA | 140 ms | 16384 KB |
1_22.txt | WA | 107 ms | 15484 KB |
1_23.txt | WA | 124 ms | 15356 KB |
1_24.txt | WA | 114 ms | 16552 KB |
1_25.txt | WA | 114 ms | 18936 KB |
1_26.txt | WA | 120 ms | 15228 KB |
1_27.txt | WA | 118 ms | 15864 KB |
1_28.txt | WA | 85 ms | 16504 KB |
1_29.txt | WA | 103 ms | 20348 KB |
2_00.txt | AC | 3 ms | 6400 KB |
2_01.txt | WA | 155 ms | 37504 KB |
2_02.txt | WA | 168 ms | 33792 KB |
2_03.txt | WA | 147 ms | 32640 KB |
2_04.txt | WA | 137 ms | 26240 KB |
2_05.txt | WA | 152 ms | 26624 KB |
2_06.txt | WA | 137 ms | 28288 KB |
2_07.txt | WA | 111 ms | 14848 KB |
2_08.txt | WA | 109 ms | 14848 KB |
2_09.txt | WA | 109 ms | 14720 KB |
2_10.txt | WA | 93 ms | 15864 KB |
2_11.txt | WA | 93 ms | 15864 KB |
2_12.txt | WA | 94 ms | 15864 KB |
2_13.txt | WA | 74 ms | 17012 KB |
2_14.txt | WA | 79 ms | 17012 KB |
2_15.txt | AC | 74 ms | 17012 KB |
2_16.txt | WA | 106 ms | 14848 KB |
2_17.txt | WA | 106 ms | 14848 KB |
2_18.txt | WA | 105 ms | 14848 KB |
2_19.txt | WA | 106 ms | 14976 KB |
2_20.txt | WA | 107 ms | 14976 KB |
2_21.txt | WA | 105 ms | 14976 KB |
2_22.txt | WA | 110 ms | 16640 KB |
2_23.txt | WA | 112 ms | 17920 KB |
2_24.txt | WA | 106 ms | 17536 KB |
2_25.txt | WA | 130 ms | 27520 KB |
2_26.txt | WA | 125 ms | 25088 KB |
2_27.txt | WA | 139 ms | 27520 KB |
2_28.txt | WA | 121 ms | 23936 KB |
2_29.txt | WA | 142 ms | 34688 KB |
2_30.txt | WA | 126 ms | 31360 KB |
2_31.txt | WA | 124 ms | 24192 KB |
2_32.txt | WA | 106 ms | 15616 KB |
2_33.txt | WA | 115 ms | 19840 KB |
2_34.txt | WA | 117 ms | 23424 KB |
2_35.txt | WA | 148 ms | 29056 KB |
2_36.txt | WA | 107 ms | 14720 KB |
2_37.txt | WA | 107 ms | 14848 KB |
2_38.txt | WA | 112 ms | 17152 KB |
2_39.txt | WA | 109 ms | 15104 KB |
2_40.txt | WA | 95 ms | 15736 KB |
2_41.txt | WA | 103 ms | 15104 KB |
2_42.txt | WA | 90 ms | 15736 KB |
2_43.txt | WA | 119 ms | 26112 KB |
2_44.txt | WA | 90 ms | 15864 KB |
2_45.txt | WA | 79 ms | 16888 KB |
2_46.txt | WA | 79 ms | 17012 KB |
2_47.txt | WA | 102 ms | 21704 KB |