Submission #1690322
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)); } 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], mx1 + 1)); else g[v] = mx + 1, low[v] = min(low[v], max(low[x], mx + 1)); } static int a[N]; int l = 0; a[++l] = g[x]; reg(i,x) if (v != fa) a[++l] = f[v] + 1; sort(a + 1, a + l + 1); a[l + 1] = 0; high[x] = max(f[x], g[x]) - 1; high[x] = min(high[x], a[2] + 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(1,0); dfs2(1,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 | 0 |
Code Size | 1785 Byte |
Status | WA |
Exec Time | 79 ms |
Memory | 17024 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 | 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 | 2 ms | 2304 KB |
0_01.txt | AC | 2 ms | 2304 KB |
0_02.txt | AC | 2 ms | 2304 KB |
1_00.txt | AC | 2 ms | 2304 KB |
1_01.txt | WA | 78 ms | 17024 KB |
1_02.txt | WA | 74 ms | 13568 KB |
1_03.txt | WA | 71 ms | 7552 KB |
1_04.txt | AC | 64 ms | 7808 KB |
1_05.txt | AC | 64 ms | 8192 KB |
1_06.txt | WA | 70 ms | 7424 KB |
1_07.txt | WA | 70 ms | 7424 KB |
1_08.txt | WA | 70 ms | 8320 KB |
1_09.txt | WA | 76 ms | 12288 KB |
1_10.txt | WA | 72 ms | 11520 KB |
1_11.txt | WA | 76 ms | 16896 KB |
1_12.txt | WA | 68 ms | 9600 KB |
1_13.txt | WA | 77 ms | 11904 KB |
1_14.txt | WA | 72 ms | 9344 KB |
1_15.txt | WA | 68 ms | 8448 KB |
1_16.txt | WA | 69 ms | 10112 KB |
1_17.txt | WA | 73 ms | 11264 KB |
1_18.txt | WA | 67 ms | 7424 KB |
1_19.txt | WA | 66 ms | 7424 KB |
1_20.txt | WA | 68 ms | 7552 KB |
1_21.txt | WA | 68 ms | 8192 KB |
1_22.txt | WA | 63 ms | 7680 KB |
1_23.txt | WA | 64 ms | 7680 KB |
1_24.txt | WA | 68 ms | 8192 KB |
1_25.txt | WA | 75 ms | 9216 KB |
1_26.txt | WA | 66 ms | 7552 KB |
1_27.txt | WA | 63 ms | 7808 KB |
1_28.txt | WA | 64 ms | 8192 KB |
1_29.txt | WA | 71 ms | 9856 KB |
2_00.txt | AC | 2 ms | 2304 KB |
2_01.txt | WA | 76 ms | 16640 KB |
2_02.txt | WA | 77 ms | 15104 KB |
2_03.txt | WA | 76 ms | 14720 KB |
2_04.txt | WA | 79 ms | 12032 KB |
2_05.txt | WA | 77 ms | 12160 KB |
2_06.txt | WA | 77 ms | 12928 KB |
2_07.txt | WA | 71 ms | 7552 KB |
2_08.txt | WA | 67 ms | 7552 KB |
2_09.txt | WA | 68 ms | 7552 KB |
2_10.txt | AC | 63 ms | 7808 KB |
2_11.txt | AC | 62 ms | 7808 KB |
2_12.txt | WA | 67 ms | 7808 KB |
2_13.txt | AC | 60 ms | 8192 KB |
2_14.txt | AC | 60 ms | 8192 KB |
2_15.txt | AC | 58 ms | 8192 KB |
2_16.txt | WA | 66 ms | 7424 KB |
2_17.txt | WA | 66 ms | 7424 KB |
2_18.txt | WA | 66 ms | 7424 KB |
2_19.txt | WA | 65 ms | 7552 KB |
2_20.txt | WA | 66 ms | 7424 KB |
2_21.txt | WA | 67 ms | 7424 KB |
2_22.txt | WA | 68 ms | 8192 KB |
2_23.txt | WA | 73 ms | 8576 KB |
2_24.txt | WA | 73 ms | 8448 KB |
2_25.txt | WA | 72 ms | 12544 KB |
2_26.txt | WA | 72 ms | 11648 KB |
2_27.txt | WA | 73 ms | 12544 KB |
2_28.txt | WA | 73 ms | 11136 KB |
2_29.txt | WA | 73 ms | 15488 KB |
2_30.txt | WA | 71 ms | 14080 KB |
2_31.txt | WA | 73 ms | 11264 KB |
2_32.txt | WA | 66 ms | 7808 KB |
2_33.txt | WA | 68 ms | 9472 KB |
2_34.txt | WA | 69 ms | 10880 KB |
2_35.txt | WA | 71 ms | 13184 KB |
2_36.txt | WA | 67 ms | 7424 KB |
2_37.txt | WA | 69 ms | 7424 KB |
2_38.txt | WA | 66 ms | 8320 KB |
2_39.txt | WA | 68 ms | 7680 KB |
2_40.txt | WA | 62 ms | 7680 KB |
2_41.txt | WA | 66 ms | 7552 KB |
2_42.txt | WA | 59 ms | 7808 KB |
2_43.txt | WA | 71 ms | 12032 KB |
2_44.txt | WA | 61 ms | 7808 KB |
2_45.txt | WA | 59 ms | 8064 KB |
2_46.txt | WA | 56 ms | 8320 KB |
2_47.txt | WA | 66 ms | 10368 KB |