QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#606226 | #9230. Routing K-Codes | maxplus | WA | 123ms | 23872kb | C++20 | 2.3kb | 2024-10-02 23:32:02 | 2024-10-02 23:32:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 2e5;
vector<int> nei[N];
int rad[N], d[N], sz[N], par[N];
uint64_t dpd[N], dpdd[N], dpu[N], dpuu[N];
int calcd(int v, int p) {
par[v] = p;
int f = v; d[v] = 0, sz[v] = 1;
for (auto u: nei[v]) if (u != p) {
int fu = calcd(u, v);
sz[v] += sz[u];
if (d[v] < d[u] + 1) d[v] = d[u] + 1, f = fu;
}
rad[v] = max(rad[v], d[v]);
return f;
}
void solved(int v, int p) {
int c = 0;
uint64_t cdpd = 1, cdpdd = 1, mn = 1e18;
for (auto u: nei[v]) if (u != p) {
solved(u, v);
cdpd += dpd[u] + dpdd[u];
cdpdd += dpdd[u] * 2;
mn = min(mn, dpdd[u]);
++c;
}
if (c > 1) cdpd += mn;
dpd[v] = cdpd;
dpdd[v] = cdpdd;
}
void solveu(int v, int p) {
uint64_t a = 0, b = 0, c = 0, sdpd = 0, sdpdd = 0;
for (auto u: nei[v]) {
auto cur = u == p? dpuu[v]: dpdd[u];
cur > a? c = b, b = a, a = cur:
cur > b? c = b, b = cur:
cur > c? c = cur: 0;
if (u != p) sdpd += dpd[u], sdpdd += dpdd[u];
else sdpdd += dpuu[v];
}
for (auto u: nei[v]) if (u != p) {
dpuu[u] = (sdpdd - dpdd[u]) * 2 + 1;
dpu[u] = dpu[v] + sdpd - dpd[u] + sdpdd - dpdd[u] + (dpdd[u] == c? b: c) + 1;
solveu(u, v);
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m, r; cin >> n >> m;
for (int i = 0, a, b; i < m; ++i) cin >> a >> b, --a, --b, nei[a].push_back(b), nei[b].push_back(a);
bool ok = 1;
for (int i = 0; i < n; ++i) ok &= nei[i].size() < 4;
if (!ok || m > n - 1 || (r = calcd(0, 0), calcd(r, r), d[r] > 64)) return cout << "NIE\n", 0;
solved(r, r);
solveu(r, r);
uint64_t ans = 1e18;
for (int i = 0; i < n; ++i) if (rad[i] <= 32) {
vector<int> nls;
int ls = -1;
for (auto u: nei[i]) !~ls && nei[u].size() == 1? ls = u, void(): nls.push_back(u);
if (nls.size() > 2) continue;
uint64_t cans = 0, a = 0, b = 0;
for (auto u: nls) {
if (u == par[i]) {
cans += dpu[i] + dpuu[i];
dpuu[i] > a? b = a, a = dpuu[i]:
dpuu[i] > b? b = dpuu[i]: 0;
} else {
cans += dpd[u] + dpdd[u];
dpdd[u] > a? b = a, a = dpdd[u]:
dpdd[u] > b? b = dpdd[u]: 0;
}
}
// cout << i << ' ' << cans + b + 1 << '\n';
ans = min(ans, cans + b + 1);
}
cout << ans;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9636kb
input:
4 3 1 2 1 3 1 4
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3760kb
input:
4 6 1 2 2 3 3 4 4 1 1 3 2 4
output:
NIE
result:
ok single line: 'NIE'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
10 10 9 3 5 10 1 4 10 8 8 3 7 3 9 6 8 6 7 2 4 5
output:
NIE
result:
ok single line: 'NIE'
Test #4:
score: -100
Wrong Answer
time: 123ms
memory: 23872kb
input:
200000 199999 172774 188052 195063 155577 38023 148303 30605 155047 170238 19344 46835 58255 154268 109062 197059 116041 136424 12058 42062 149807 109545 115380 132322 51106 16706 162612 62234 31319 195735 80435 173898 84051 19876 102910 186924 9136 123094 117097 145054 173049 137364 152731 82662 18...
output:
34814606819805
result:
wrong answer 1st lines differ - expected: 'NIE', found: '34814606819805'