0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-10 00:18:48 +00:00

4289. [PA2012] Tax

https://hydro.ac/d/bzoj/record/63b6c570291ec3514f4e2803
This commit is contained in:
Baoshuo Ren 2023-01-05 20:41:36 +08:00
parent eb68f6eab3
commit a0111ea702
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
23 changed files with 174 additions and 0 deletions

108
BZOJ/4289/4289.cpp Normal file
View File

@ -0,0 +1,108 @@
#include <iostream>
#include <algorithm>
#include <functional>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>
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<std::tuple<int, int, int>> g[N];
std::vector<std::pair<int, int>> 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::pair<long long, int>, std::vector<std::pair<long long, int>>, 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<int, int, int> &lhs, const std::tuple<int, int, int> &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;
}

BIN
BZOJ/4289/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4289/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.