Submission #1690771
Source Code Expand
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <vector> #include <set> #include <map> #include <algorithm> #define rep(i,a,b) for(int i = a; i <= b; i++) #define dep(i,a,b) for(int i = a; i >= b; i--) #define Rep(i,a) for(int i = 0; i < a; i++) using namespace std; typedef long long LL; typedef pair<int, int> pii; #define x first #define y second #define pb(a) push_back(a) const int N = 2e5 + 10; int n; char s[N]; struct edge{ int to, pre; } e[N << 1]; int u[N], l = 0; void ins(int a, int b) { e[++l] = (edge){b, u[a]}, u[a] = l; } #define v e[i].to #define reg(i,a) for(int i = u[a]; i; i = e[i].pre) int f[N], g[N], high[N], low[N]; void dfs(int x, int fa) { if (s[x] == '1') low[x] = 0; else low[x] = n; reg(i,x) if (v != fa) { dfs(v, x), f[x] = max(f[x], f[v] + 1), low[x] = min(low[x], max(f[v] + 1, low[v] + 1)); } } int a[N]; void dfs2(int x, int fa) { int mx = g[x], mxa = 0, mx1 = 0; reg(i,x) if (v != fa) { if (f[v] + 1 >= mx) mx1 = mx, mx = f[v] + 1, mxa = v; else if (f[v] + 1 > mx1) mx1 = f[v] + 1; } reg(i,x) if (v != fa) { if (v == mxa) g[v] = mx1 + 1, low[v] = min(low[v], max(low[x] + 1, mx1 + 1)); else g[v] = mx + 1, low[v] = min(low[v], max(low[x] + 1, mx + 1)); } high[x] = max(f[x], g[x]) - 1; high[x] = min(high[x], mx1 + 1); reg(i,x) if (v != fa) dfs2(v, x); } int main() { scanf("%d",&n); rep(i,1,n - 1) { int a, b; scanf("%d%d",&a,&b); ins(a, b), ins(b, a); } scanf("%s",s + 1); dfs(3,0); dfs2(3,0); LL ans = 1; rep(i,1,n) if (low[i] <= high[i]) ans += high[i] - low[i] + 1; printf("%lld\n",ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Black Radius |
User | WuHongxun |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 1688 Byte |
Status | WA |
Exec Time | 63 ms |
Memory | 16128 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:54:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:56:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int a, b; scanf("%d%d",&a,&b); ^ ./Main.cpp:59:19: 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 | 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 | 2 ms | 4352 KB |
0_01.txt | AC | 2 ms | 4352 KB |
0_02.txt | AC | 2 ms | 4352 KB |
1_00.txt | AC | 2 ms | 4352 KB |
1_01.txt | AC | 62 ms | 14080 KB |
1_02.txt | AC | 61 ms | 10752 KB |
1_03.txt | AC | 58 ms | 7552 KB |
1_04.txt | AC | 52 ms | 7424 KB |
1_05.txt | AC | 49 ms | 7424 KB |
1_06.txt | AC | 55 ms | 7424 KB |
1_07.txt | AC | 55 ms | 7424 KB |
1_08.txt | AC | 56 ms | 8064 KB |
1_09.txt | AC | 60 ms | 10368 KB |
1_10.txt | AC | 58 ms | 10752 KB |
1_11.txt | AC | 62 ms | 13440 KB |
1_12.txt | AC | 58 ms | 9088 KB |
1_13.txt | AC | 60 ms | 10368 KB |
1_14.txt | AC | 56 ms | 8704 KB |
1_15.txt | AC | 56 ms | 8576 KB |
1_16.txt | AC | 58 ms | 9728 KB |
1_17.txt | AC | 61 ms | 11776 KB |
1_18.txt | AC | 56 ms | 7424 KB |
1_19.txt | AC | 55 ms | 7424 KB |
1_20.txt | AC | 56 ms | 7552 KB |
1_21.txt | AC | 58 ms | 7936 KB |
1_22.txt | AC | 53 ms | 7424 KB |
1_23.txt | AC | 55 ms | 7424 KB |
1_24.txt | AC | 56 ms | 7936 KB |
1_25.txt | AC | 54 ms | 8576 KB |
1_26.txt | AC | 52 ms | 7296 KB |
1_27.txt | AC | 51 ms | 7424 KB |
1_28.txt | AC | 50 ms | 7680 KB |
1_29.txt | AC | 56 ms | 10240 KB |
2_00.txt | WA | 2 ms | 4352 KB |
2_01.txt | AC | 63 ms | 14848 KB |
2_02.txt | AC | 61 ms | 12416 KB |
2_03.txt | AC | 63 ms | 13440 KB |
2_04.txt | AC | 62 ms | 12928 KB |
2_05.txt | AC | 61 ms | 11776 KB |
2_06.txt | AC | 62 ms | 13696 KB |
2_07.txt | AC | 58 ms | 7552 KB |
2_08.txt | AC | 58 ms | 7552 KB |
2_09.txt | AC | 58 ms | 7552 KB |
2_10.txt | AC | 52 ms | 7424 KB |
2_11.txt | AC | 51 ms | 7424 KB |
2_12.txt | AC | 52 ms | 7424 KB |
2_13.txt | AC | 47 ms | 7424 KB |
2_14.txt | AC | 46 ms | 7424 KB |
2_15.txt | AC | 47 ms | 7424 KB |
2_16.txt | AC | 55 ms | 7424 KB |
2_17.txt | AC | 55 ms | 7424 KB |
2_18.txt | AC | 56 ms | 7424 KB |
2_19.txt | AC | 55 ms | 7552 KB |
2_20.txt | AC | 55 ms | 7424 KB |
2_21.txt | AC | 56 ms | 7424 KB |
2_22.txt | AC | 57 ms | 8192 KB |
2_23.txt | AC | 57 ms | 8064 KB |
2_24.txt | AC | 58 ms | 8192 KB |
2_25.txt | AC | 61 ms | 11904 KB |
2_26.txt | AC | 61 ms | 11264 KB |
2_27.txt | AC | 61 ms | 11392 KB |
2_28.txt | AC | 58 ms | 9856 KB |
2_29.txt | AC | 63 ms | 16128 KB |
2_30.txt | AC | 61 ms | 12928 KB |
2_31.txt | AC | 61 ms | 11136 KB |
2_32.txt | AC | 55 ms | 7680 KB |
2_33.txt | AC | 57 ms | 8960 KB |
2_34.txt | AC | 59 ms | 10240 KB |
2_35.txt | AC | 60 ms | 11008 KB |
2_36.txt | AC | 57 ms | 7424 KB |
2_37.txt | AC | 60 ms | 7424 KB |
2_38.txt | AC | 57 ms | 7936 KB |
2_39.txt | AC | 58 ms | 7552 KB |
2_40.txt | AC | 52 ms | 7424 KB |
2_41.txt | AC | 55 ms | 7424 KB |
2_42.txt | AC | 50 ms | 7424 KB |
2_43.txt | AC | 58 ms | 9216 KB |
2_44.txt | AC | 50 ms | 7424 KB |
2_45.txt | AC | 48 ms | 7424 KB |
2_46.txt | AC | 48 ms | 7552 KB |
2_47.txt | AC | 56 ms | 9472 KB |