From a0111ea70214955ac4a27aa7a474bfeedea392ed Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 5 Jan 2023 20:41:36 +0800 Subject: [PATCH] 4289. [PA2012] Tax https://hydro.ac/d/bzoj/record/63b6c570291ec3514f4e2803 --- BZOJ/4289/4289.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++ BZOJ/4289/data/1.in | 3 ++ BZOJ/4289/data/1.out | 3 ++ BZOJ/4289/data/10.in | 3 ++ BZOJ/4289/data/10.out | 3 ++ BZOJ/4289/data/11.in | 3 ++ BZOJ/4289/data/11.out | 3 ++ BZOJ/4289/data/2.in | 3 ++ BZOJ/4289/data/2.out | 3 ++ BZOJ/4289/data/3.in | 3 ++ BZOJ/4289/data/3.out | 3 ++ BZOJ/4289/data/4.in | 3 ++ BZOJ/4289/data/4.out | 3 ++ BZOJ/4289/data/5.in | 3 ++ BZOJ/4289/data/5.out | 3 ++ BZOJ/4289/data/6.in | 3 ++ BZOJ/4289/data/6.out | 3 ++ BZOJ/4289/data/7.in | 3 ++ BZOJ/4289/data/7.out | 3 ++ BZOJ/4289/data/8.in | 3 ++ BZOJ/4289/data/8.out | 3 ++ BZOJ/4289/data/9.in | 3 ++ BZOJ/4289/data/9.out | 3 ++ 23 files changed, 174 insertions(+) create mode 100644 BZOJ/4289/4289.cpp create mode 100644 BZOJ/4289/data/1.in create mode 100644 BZOJ/4289/data/1.out create mode 100644 BZOJ/4289/data/10.in create mode 100644 BZOJ/4289/data/10.out create mode 100644 BZOJ/4289/data/11.in create mode 100644 BZOJ/4289/data/11.out create mode 100644 BZOJ/4289/data/2.in create mode 100644 BZOJ/4289/data/2.out create mode 100644 BZOJ/4289/data/3.in create mode 100644 BZOJ/4289/data/3.out create mode 100644 BZOJ/4289/data/4.in create mode 100644 BZOJ/4289/data/4.out create mode 100644 BZOJ/4289/data/5.in create mode 100644 BZOJ/4289/data/5.out create mode 100644 BZOJ/4289/data/6.in create mode 100644 BZOJ/4289/data/6.out create mode 100644 BZOJ/4289/data/7.in create mode 100644 BZOJ/4289/data/7.out create mode 100644 BZOJ/4289/data/8.in create mode 100644 BZOJ/4289/data/8.out create mode 100644 BZOJ/4289/data/9.in create mode 100644 BZOJ/4289/data/9.out diff --git a/BZOJ/4289/4289.cpp b/BZOJ/4289/4289.cpp new file mode 100644 index 00000000..280c634f --- /dev/null +++ b/BZOJ/4289/4289.cpp @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5, + M = 2e5 + 5; +const long long INF = 0x3f3f3f3f'3f3f3f3f; + +int n, m, s, t; +std::vector> g[N]; +std::vector> g2[M << 1]; +long long dist[M << 1]; +bool vis[M << 1]; + +void dijkstra() { + std::fill(std::begin(dist), std::end(dist), INF); + std::fill(std::begin(vis), std::end(vis), false); + + std::priority_queue, std::vector>, std::greater<>> q; + + q.emplace(0, s); + dist[s] = 0; + + while (!q.empty()) { + long long l; + int u; + + std::tie(l, u) = q.top(); + + q.pop(); + + if (vis[u]) continue; + + for (auto e : g2[u]) { + int v = e.first, + w = e.second; + + if (dist[v] > l + w) { + dist[v] = l + w; + + q.emplace(dist[v], v); + } + } + + vis[u] = true; + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1, u, v, w; i <= m; i++) { + cin >> u >> v >> w; + + g[u].emplace_back(v, w, i << 1); + g[v].emplace_back(u, w, i << 1 | 1); + } + + s = 0, t = 2 * m + 2; + + for (int i = 1; i <= n; i++) { + std::sort(g[i].begin(), g[i].end(), [](const std::tuple &lhs, const std::tuple &rhs) { + return std::get<1>(lhs) < std::get<1>(rhs); + }); + + for (int j = 0; j < g[i].size(); j++) { + int v, w, id; + + std::tie(v, w, id) = g[i][j]; + + g2[id ^ 1].emplace_back(id, w); + + if (i == 1) { + g2[s].emplace_back(id, w); + } + + if (v == n) { + g2[id].emplace_back(t, w); + } + + if (j != 0) { + int w2, id2; + + std::tie(std::ignore, w2, id2) = g[i][j - 1]; + + g2[id2].emplace_back(id, w - w2); + g2[id].emplace_back(id2, 0); + } + } + } + + dijkstra(); + + cout << dist[t] << endl; + + return 0; +} diff --git a/BZOJ/4289/data/1.in b/BZOJ/4289/data/1.in new file mode 100644 index 00000000..bcf98f56 --- /dev/null +++ b/BZOJ/4289/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9999630308725747bf60f86ad627e0f4db98b56e412f3e2d449cd90c93b345ba +size 3518465 diff --git a/BZOJ/4289/data/1.out b/BZOJ/4289/data/1.out new file mode 100644 index 00000000..0d3dc250 --- /dev/null +++ b/BZOJ/4289/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88bef4630480a04bf9ef5e4d9cf0312e9f0e2b0f136382d7ad1f29e57ff212f9 +size 11 diff --git a/BZOJ/4289/data/10.in b/BZOJ/4289/data/10.in new file mode 100644 index 00000000..2ad0f4ef --- /dev/null +++ b/BZOJ/4289/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a83ad733b2d3f6e7e82457872c54e6bbd775957fd6274d0d62b45d10adfdb60 +size 2605648 diff --git a/BZOJ/4289/data/10.out b/BZOJ/4289/data/10.out new file mode 100644 index 00000000..937c3cc8 --- /dev/null +++ b/BZOJ/4289/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7e8645a277415fdaf1f3771039b2234612ff5b7d4f65352cd36473f9ed6451bc +size 8 diff --git a/BZOJ/4289/data/11.in b/BZOJ/4289/data/11.in new file mode 100644 index 00000000..3b34b8a4 --- /dev/null +++ b/BZOJ/4289/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08704f5bf5b25471161680a7107e6b186fa68d3fbc2bdf0498f5790de8db8132 +size 16 diff --git a/BZOJ/4289/data/11.out b/BZOJ/4289/data/11.out new file mode 100644 index 00000000..0fca306a --- /dev/null +++ b/BZOJ/4289/data/11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f5bbc9df805e66180e1640add85a5de00bf2e13d1f5415e22278318f2d82d5d1 +size 8 diff --git a/BZOJ/4289/data/2.in b/BZOJ/4289/data/2.in new file mode 100644 index 00000000..3e13756e --- /dev/null +++ b/BZOJ/4289/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5dc209a74540f12470b8b490024338371577db8fdd9b053674a9a5bc4d4246ef +size 3733358 diff --git a/BZOJ/4289/data/2.out b/BZOJ/4289/data/2.out new file mode 100644 index 00000000..ed613cc8 --- /dev/null +++ b/BZOJ/4289/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:550baea349f87a0277d3be4dd70d26d1ed6bc23ad47aeeaf9b475d1ee72218e8 +size 11 diff --git a/BZOJ/4289/data/3.in b/BZOJ/4289/data/3.in new file mode 100644 index 00000000..ab13c834 --- /dev/null +++ b/BZOJ/4289/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c250f8f5883c4b547a399870a8d987beede6d34a2f3074521817fa46cab820ed +size 116784 diff --git a/BZOJ/4289/data/3.out b/BZOJ/4289/data/3.out new file mode 100644 index 00000000..716ef47b --- /dev/null +++ b/BZOJ/4289/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a6e462d6c4a49b30ec70d053affdfe534febda936618e9fae4ba2cc14c1fc58c +size 5 diff --git a/BZOJ/4289/data/4.in b/BZOJ/4289/data/4.in new file mode 100644 index 00000000..99d010f3 --- /dev/null +++ b/BZOJ/4289/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bfb43d46a337019f6cd3a9475c970f12e4964b40e55a21ac4b294e6bef4f5939 +size 151546 diff --git a/BZOJ/4289/data/4.out b/BZOJ/4289/data/4.out new file mode 100644 index 00000000..4ceb9dbd --- /dev/null +++ b/BZOJ/4289/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:928c632e3bdcbdc20891f6b9a74e7fb08a22bf6d6d891ce94f1fa963a1ef8127 +size 5 diff --git a/BZOJ/4289/data/5.in b/BZOJ/4289/data/5.in new file mode 100644 index 00000000..f260270b --- /dev/null +++ b/BZOJ/4289/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29ddc73dc3f51d007c911b7922039bc08d905c3b6c1bc9697b6be44c28396e0d +size 2551858 diff --git a/BZOJ/4289/data/5.out b/BZOJ/4289/data/5.out new file mode 100644 index 00000000..3abe0fd8 --- /dev/null +++ b/BZOJ/4289/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:12ddc23e0c6d51e77ac2b73879998b1a728c8659c49e8bbac9835a2384784429 +size 6 diff --git a/BZOJ/4289/data/6.in b/BZOJ/4289/data/6.in new file mode 100644 index 00000000..83229152 --- /dev/null +++ b/BZOJ/4289/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad22334c661738890b342efab0404c31f6fb459290cb58cd85012a3f15dc4866 +size 2910983 diff --git a/BZOJ/4289/data/6.out b/BZOJ/4289/data/6.out new file mode 100644 index 00000000..5d694f38 --- /dev/null +++ b/BZOJ/4289/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c2045df03b92279502faee523f8550c8201f2501bb485011df745873703c37c1 +size 8 diff --git a/BZOJ/4289/data/7.in b/BZOJ/4289/data/7.in new file mode 100644 index 00000000..1aa13aea --- /dev/null +++ b/BZOJ/4289/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:918ee95b4aae7991af2892948f9089e9b34878f828319d30540c2e7829c5374c +size 40 diff --git a/BZOJ/4289/data/7.out b/BZOJ/4289/data/7.out new file mode 100644 index 00000000..c65f1158 --- /dev/null +++ b/BZOJ/4289/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a252402972f6057fa53cc172b52b9ffca698e18311facd0f3b06ecaaef79e17 +size 3 diff --git a/BZOJ/4289/data/8.in b/BZOJ/4289/data/8.in new file mode 100644 index 00000000..7b4fc707 --- /dev/null +++ b/BZOJ/4289/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:68aafb391b3105b8576dffc0d1a103d1e0765c0e12bf9f07effc2a52e888cbfb +size 34 diff --git a/BZOJ/4289/data/8.out b/BZOJ/4289/data/8.out new file mode 100644 index 00000000..396b6814 --- /dev/null +++ b/BZOJ/4289/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1fb50e6c86fae1679ef3351296fd6713411a08cf8dd1790a4fd05fae8688164 +size 3 diff --git a/BZOJ/4289/data/9.in b/BZOJ/4289/data/9.in new file mode 100644 index 00000000..53d37bd4 --- /dev/null +++ b/BZOJ/4289/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e1f1a9f0f590f7c5af4f75ab3c522cfa16d954ac615e0d2611d251a11ed9ca8 +size 2791849 diff --git a/BZOJ/4289/data/9.out b/BZOJ/4289/data/9.out new file mode 100644 index 00000000..892a567f --- /dev/null +++ b/BZOJ/4289/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e695e884a08a0a5aa10526c27ad4b65399a95449fc94dc7eb7cbd6a596352ed +size 7