版本比较
11.17 周作业 44
正文
增加 5 行删除 5 行
47 行未改动48495051525253545556177 行未改动全部展开234235236237238238239240241242201 行未改动全部展开4444454464474484484494504514523 行未改动45645745845946046046146246246346446546617 行未改动47 行未改动 puts(""); return 0;}signed main(){ for (int T = rd(); T--;) Main(); for (int T = rd(); T--;) Main(); return 0;}
```177 行未改动全部展开 ans = (pw[n] - n - 1 + P) % P; for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++){ int d = x[j] - x[i], l = lower_bound(x + 1, x + n + 1, x[i] - d) - x, r = lower_bound(x + 1, x + n + 1, x[j] + d) - x - 1; int tmp = 1ll * (pw[i - l] + P - 1) % P * (pw[r - j] + P - 1) % P * pw[l - 1] % P * pw[n - r] % P; ans = (ans + tmp) % P; ans = (ans + tmp) % P; } printf ("%d\n", ans); return 0;}201 行未改动全部展开signed main(){ n = rd(); for (int i = 2; i <= n; i++) fa[i] = rd(), e[fa[i]].push_back(i), du[fa[i]]++; dep[1] = -1, dfs(1);
if (du[1] == n - 1){ cout << 1 << endl; for (int i = 2; i <= n; i++) printf ("1 "); cout << endl; while (1){3 行未改动 cout << 1 << endl; } return 0; }
if (work()) return 0;
for (int i = 2; i <= n; i++) col[i] = dep[i] % 3 + 1; cout << 3 << endl; for (int i = 2; i <= n; i++) printf ("%d ", col[i]); cout << endl; while (1){17 行未改动