Submission #1071722
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pii pair<int,int> #define pll pair<ll,ll> #define pdd pair<double,double> #define X first #define Y second #define REP(i,a) for(int i=0;i<a;++i) #define REPP(i,a,b) for(int i=a;i<b;++i) #define FILL(a,x) memset(a,x,sizeof(a)) #define foreach( gg,itit ) for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ ) #define mp make_pair #define pb push_back #define all(s) s.begin(),s.end() #define present(c,x) ((c).find(x) != (c).end()) const double EPS = 1e-8; const int mod = 1e9+7; const int N = 1e6+10; const ll INF = 1e18; //#define DEBUG ll power(ll x,ll y){ ll t=1; while(y>0){ if(y%2) y-=1,t=t*x%mod; else y/=2,x=x*x%mod; } return t; } #ifdef DEBUG #define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__) #else #define dprintf(fmt,...) #endif vector<int> G[N]; char s[N]; int mx[N],sub[N],mn[N],lw[N]; void dfs(int v,int p){ sub[v]=0; if(s[v]=='1') lw[v]=1; REP(i,G[v].size()) if(G[v][i]!=p) { dfs(G[v][i],v); lw[v]|=lw[G[v][i]]; sub[v]=max(sub[v],sub[G[v][i]]+1); } } void dfs1(int v,int p,int l,int ik){ pii arr[2]; FILL(arr,0); mn[v]=mod; if(ik) mn[v]=l; arr[0]=mp(l,p); REP(i,G[v].size()) if(G[v][i]!=p) { pii z = mp(sub[G[v][i]]+1,G[v][i]); if(lw[G[v][i]]) mn[v]=min(mn[v],sub[G[v][i]]+1); ik+=lw[G[v][i]]; if(z>arr[0]) arr[1]=arr[0],arr[0]=z; else arr[1]=max(arr[1],z); } if(s[v]=='1') mn[v]=0,ik++; mx[v]=min(arr[0].X-1,arr[1].X+1); // printf("%d %d\n",v+1,mx[v]+1); REP(i,G[v].size()) if(G[v][i]!=p){ int p = (ik>lw[G[v][i]]); if(G[v][i]!=arr[0].Y) dfs1(G[v][i],v,arr[0].X+1,p); else dfs1(G[v][i],v,arr[1].X+1,p); } } int main(){ int n; scanf("%d",&n); REP(i,n-1){ int x,y; scanf("%d%d",&x,&y); x--;y--; G[x].pb(y); G[y].pb(x); } scanf("%s",s); dfs(0,-1); dfs1(0,-1,0,0); ll ans=1; REP(i,n) if(mn[i]<=mx[i]) ans+=mx[i]-mn[i]+1; printf("%lld\n",ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Black Radius |
User | alecsyde |
Language | C++14 (GCC 5.4.1) |
Score | 1900 |
Code Size | 2062 Byte |
Status | AC |
Exec Time | 176 ms |
Memory | 49920 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:72:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int n; scanf("%d",&n); ^ ./Main.cpp:74:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int x,y; scanf("%d%d",&x,&y); x--;y--; ^ ./Main.cpp:77:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s",s); ^
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 | 27 ms | 23680 KB |
0_01.txt | AC | 27 ms | 23680 KB |
0_02.txt | AC | 27 ms | 23680 KB |
1_00.txt | AC | 27 ms | 23680 KB |
1_01.txt | AC | 168 ms | 49920 KB |
1_02.txt | AC | 159 ms | 44032 KB |
1_03.txt | AC | 155 ms | 33408 KB |
1_04.txt | AC | 122 ms | 33656 KB |
1_05.txt | AC | 106 ms | 34036 KB |
1_06.txt | AC | 134 ms | 33536 KB |
1_07.txt | AC | 133 ms | 33536 KB |
1_08.txt | AC | 137 ms | 34816 KB |
1_09.txt | AC | 151 ms | 41600 KB |
1_10.txt | AC | 149 ms | 40320 KB |
1_11.txt | AC | 172 ms | 49792 KB |
1_12.txt | AC | 137 ms | 36992 KB |
1_13.txt | AC | 151 ms | 40960 KB |
1_14.txt | AC | 139 ms | 36608 KB |
1_15.txt | AC | 138 ms | 35200 KB |
1_16.txt | AC | 144 ms | 37888 KB |
1_17.txt | AC | 152 ms | 39808 KB |
1_18.txt | AC | 136 ms | 33280 KB |
1_19.txt | AC | 136 ms | 33408 KB |
1_20.txt | AC | 136 ms | 33408 KB |
1_21.txt | AC | 141 ms | 34432 KB |
1_22.txt | AC | 127 ms | 33532 KB |
1_23.txt | AC | 131 ms | 33532 KB |
1_24.txt | AC | 136 ms | 34560 KB |
1_25.txt | AC | 139 ms | 36088 KB |
1_26.txt | AC | 130 ms | 33276 KB |
1_27.txt | AC | 123 ms | 33656 KB |
1_28.txt | AC | 117 ms | 34296 KB |
1_29.txt | AC | 149 ms | 37244 KB |
2_00.txt | AC | 28 ms | 23680 KB |
2_01.txt | AC | 176 ms | 49280 KB |
2_02.txt | AC | 161 ms | 46720 KB |
2_03.txt | AC | 163 ms | 45824 KB |
2_04.txt | AC | 157 ms | 41344 KB |
2_05.txt | AC | 157 ms | 41600 KB |
2_06.txt | AC | 157 ms | 42752 KB |
2_07.txt | AC | 142 ms | 33280 KB |
2_08.txt | AC | 138 ms | 33408 KB |
2_09.txt | AC | 150 ms | 33280 KB |
2_10.txt | AC | 121 ms | 33656 KB |
2_11.txt | AC | 120 ms | 33656 KB |
2_12.txt | AC | 123 ms | 33656 KB |
2_13.txt | AC | 106 ms | 33268 KB |
2_14.txt | AC | 105 ms | 33908 KB |
2_15.txt | AC | 106 ms | 34036 KB |
2_16.txt | AC | 139 ms | 33536 KB |
2_17.txt | AC | 132 ms | 33536 KB |
2_18.txt | AC | 134 ms | 33536 KB |
2_19.txt | AC | 133 ms | 33536 KB |
2_20.txt | AC | 132 ms | 33536 KB |
2_21.txt | AC | 149 ms | 33536 KB |
2_22.txt | AC | 137 ms | 34688 KB |
2_23.txt | AC | 137 ms | 35456 KB |
2_24.txt | AC | 140 ms | 35200 KB |
2_25.txt | AC | 150 ms | 42240 KB |
2_26.txt | AC | 149 ms | 40576 KB |
2_27.txt | AC | 157 ms | 42240 KB |
2_28.txt | AC | 145 ms | 39808 KB |
2_29.txt | AC | 162 ms | 47232 KB |
2_30.txt | AC | 155 ms | 44928 KB |
2_31.txt | AC | 151 ms | 39936 KB |
2_32.txt | AC | 134 ms | 33920 KB |
2_33.txt | AC | 141 ms | 36864 KB |
2_34.txt | AC | 147 ms | 39296 KB |
2_35.txt | AC | 154 ms | 43264 KB |
2_36.txt | AC | 138 ms | 33280 KB |
2_37.txt | AC | 137 ms | 33280 KB |
2_38.txt | AC | 138 ms | 34944 KB |
2_39.txt | AC | 138 ms | 33536 KB |
2_40.txt | AC | 124 ms | 33528 KB |
2_41.txt | AC | 130 ms | 33408 KB |
2_42.txt | AC | 119 ms | 33528 KB |
2_43.txt | AC | 155 ms | 41344 KB |
2_44.txt | AC | 121 ms | 33656 KB |
2_45.txt | AC | 113 ms | 33912 KB |
2_46.txt | AC | 113 ms | 34164 KB |
2_47.txt | AC | 134 ms | 38264 KB |