From 777488a777607abc2585fe276b88da1299fa4574 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Wed, 10 Sep 2025 23:00:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4P9981.cpp?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E5=86=97=E4=BD=99=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 清理未使用的代码,仅保留main函数框架以简化文件 --- src/9/10/P9981.cpp | 199 +-------------------------------------------- 1 file changed, 3 insertions(+), 196 deletions(-) diff --git a/src/9/10/P9981.cpp b/src/9/10/P9981.cpp index cdfc720..294989d 100644 --- a/src/9/10/P9981.cpp +++ b/src/9/10/P9981.cpp @@ -1,196 +1,3 @@ -#include -#include -#include -#include - -namespace FastIO { -const int BUF_SIZE = 1 << 20; -char in_buf[BUF_SIZE], out_buf[BUF_SIZE]; -char *in_ptr = in_buf + BUF_SIZE; -char *out_ptr = out_buf; - -char get_char() { - if (in_ptr == in_buf + BUF_SIZE) { - fread(in_buf, 1, BUF_SIZE, stdin); - in_ptr = in_buf; - } - return *(in_ptr++); -} - -template void read(T &x) { - x = 0; - char c = get_char(); - bool positive = true; - while (!isdigit(c)) { - if (c == '-') - positive = false; - c = get_char(); - } - while (isdigit(c)) { - x = x * 10 + (c - '0'); - c = get_char(); - } - if (!positive) - x = -x; -} - -void put_char(char c) { - if (out_ptr == out_buf + BUF_SIZE) { - fwrite(out_buf, 1, BUF_SIZE, stdout); - out_ptr = out_buf; - } - *(out_ptr++) = c; -} - -template void write(T x) { - if (x < 0) { - put_char('-'); - x = -x; - } - if (x == 0) { - put_char('0'); - return; - } - char buf[20]; - int len = 0; - while (x > 0) { - buf[len++] = (x % 10) + '0'; - x /= 10; - } - for (int i = len - 1; i >= 0; --i) { - put_char(buf[i]); - } -} - -struct Flusher { - ~Flusher() { - if (out_ptr != out_buf) { - fwrite(out_buf, 1, out_ptr - out_buf, stdout); - } - } -} flusher; -} // namespace FastIO - -using FastIO::put_char; -using FastIO::read; -using FastIO::write; - -struct Edge { - int to; - int label; -}; - -struct Path { - long long len = 0; - long long sum = 0; - int prefix_label = 0; - int next_node = 0; -}; - -bool is_better(const Path &p_cand, const Path &p_best, const std::vector &dp) { - if (p_cand.len > p_best.len) - return true; - if (p_cand.len < p_best.len) - return false; - - if (p_cand.len == 0) - return false; - - if (p_cand.prefix_label < p_best.prefix_label) - return true; - if (p_cand.prefix_label > p_best.prefix_label) - return false; - - const Path *ptr1 = &dp[p_cand.next_node]; - const Path *ptr2 = &dp[p_best.next_node]; - - for (int i = 0; i < 110 && ptr1->len > 0 && ptr2->len > 0; ++i) { - if (ptr1->prefix_label < ptr2->prefix_label) - return true; - if (ptr1->prefix_label > ptr2->prefix_label) - return false; - ptr1 = &dp[ptr1->next_node]; - ptr2 = &dp[ptr2->next_node]; - } - - return false; -} - -int main() { - std::ios_base::sync_with_stdio(false); - std::cin.tie(NULL); - - int n, m; - read(n); - read(m); - - std::vector> adj(n + 1); - std::vector in_degree(n + 1, 0); - - for (int i = 0; i < m; ++i) { - int u, v, l; - read(u); - read(v); - read(l); - adj[u].push_back({v, l}); - in_degree[v]++; - } - - std::queue q; - for (int i = 1; i <= n; ++i) { - if (in_degree[i] == 0) { - q.push(i); - } - } - - std::vector topo_order; - topo_order.reserve(n); - while (!q.empty()) { - int u = q.front(); - q.pop(); - topo_order.push_back(u); - - for (const auto &edge : adj[u]) { - int v = edge.to; - in_degree[v]--; - if (in_degree[v] == 0) { - q.push(v); - } - } - } - - std::vector dp(n + 1); - - for (int i = n - 1; i >= 0; --i) { - int u = topo_order[i]; - - std::sort(adj[u].begin(), adj[u].end(), [](const Edge &a, const Edge &b) { return a.label < b.label; }); - - Path best_path = {}; - - for (const auto &edge : adj[u]) { - int v = edge.to; - int l = edge.label; - - Path candidate_path; - candidate_path.len = 1 + dp[v].len; - candidate_path.sum = l + dp[v].sum; - candidate_path.prefix_label = l; - candidate_path.next_node = v; - - if (is_better(candidate_path, best_path, dp)) { - best_path = candidate_path; - } - } - dp[u] = best_path; - } - - for (int i = 1; i <= n; ++i) { - write(dp[i].len); - put_char(' '); - write(dp[i].sum); - put_char('\n'); - } - - return 0; -} +int main(){ + +} \ No newline at end of file