QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#770850 | #7883. Takeout Delivering | fosov | WA | 154ms | 40728kb | C++14 | 1.9kb | 2024-11-22 00:50:32 | 2024-11-22 00:50:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lll __int128
#define INF 0x3f3f3f3f
#define LNF 0x3f3f3f3f3f3f3f3fll
#define MOD 998244353
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ld long double
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define N 300010
#define K 22
vector<pii> G[N];
int w1[N], w2[N];
void add_edge(int u, int v, int l) {
G[u].emplace_back(v, l);
G[v].emplace_back(u, l);
}
void dfs1(int u, int fa, int w) {
w1[u] = w;
for (auto [v, l] : G[u]) {
if (v == fa) continue;
dfs1(v, u, max(w, l));
}
}
void dfs2(int u, int fa, int w) {
w2[u] = w;
for (auto [v, l] : G[u]) {
if (v == fa) continue;
dfs2(v, u, max(w, l));
}
}
int p[N];
void init(int n) {
for (int i = 1; i <= n; ++ i) p[i] = i;
}
int find(int x) {
return p[x] == x ? x : (p[x] = find(p[x]));
}
void join(int u, int v, int l) {
if (find(u) == find(v)) return;
add_edge(u, v, l);
p[find(u)] = find(v);
}
int main() {
#ifdef TEST
freopen("zz.in", "r+", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m; cin >> n >> m;
init(n);
vector<tuple<int, int, int>> edgs;
for (int i = 0; i < m; ++ i) {
int u, v, l; cin >> u >> v >> l;
edgs.emplace_back(l, u, v);
}
int res = INF;
sort(all(edgs)), reverse(all(edgs));
for (auto [l, u, v] : edgs) join(u, v, l);
for (int i = 1; i <= n; ++ i) w1[i] = w2[i] = -1;
dfs1(1, 1, 0);
dfs2(n, n, 0);
for (auto [l, u, v] : edgs) {
if (w1[u] != -1 && w2[v] != -1 && min(w1[u], w2[v]) <= l) {
res = min(res, l + max(w1[u], w2[v]));
}
if (w2[u] != -1 && w1[v] != -1 && min(w2[u], w1[v]) <= l) {
res = min(res, l + max(w2[u], w1[v]));
}
}
cout << res << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 12840kb
input:
4 6 1 2 2 1 3 4 1 4 7 2 3 1 2 4 3 3 4 9
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: -100
Wrong Answer
time: 154ms
memory: 40728kb
input:
300000 299999 80516 80517 597830404 110190 110191 82173886 218008 218009 954561262 250110 250111 942489774 66540 66541 156425292 34947 34948 239499776 273789 273790 453201232 84428 84429 439418398 98599 98600 326095035 55636 55637 355015760 158611 158612 684292473 43331 43332 43265001 171621 171622 ...
output:
1061109567
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '1061109567'