QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#275324 | #7883. Takeout Delivering | CSUST_GXL | Compile Error | / | / | C++20 | 2.6kb | 2023-12-04 16:44:18 | 2023-12-04 16:44:18 |
Judging History
你现在查看的是最新测评结果
- [2023-12-06 22:45:03]
- hack成功,自动添加数据
- (//qoj.ac/hack/491)
- [2023-12-04 16:44:18]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-12-04 16:44:18]
- 提交
answer
#include<unordered_map>
#include<functional>
#include<algorithm>
#include<windows.h>
#include<iostream>
#include<cassert>
#include<cstring>
#include<cstdlib>
#include<numeric>
#include<iomanip>
#include<bitset>
#include<random>
#include<cstdio>
#include<string>
#include<vector>
#include<array>
#include<ctime>
#include<stack>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#define fi first
#define se second
#define pii pair<int,int>
#define NO cout << "NO\n"
#define YES cout << "YES\n"
#define stop system("pause");
#define debug printf("++ ++\n");
#define cout(a) cout << (#a) << " = " << a << endl;
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 3e5;
random_device gen;
mt19937 rnd(gen());
int n, m;
int dis1[N + 5], disn[N + 5];
vector<array<int, 3> > e;
vector<pii > G[N + 5];
/* 终点是一切概率的结束,也是一切期望的开始 */
/* *
* 可能做法: 基础算法(思维, 暴力, 贪心) / 图论
* */
struct DSU {
std::vector<int> pre, sz;
DSU(int n) : pre(n + 1), sz(n + 1, 1) {
std::iota(pre.begin(), pre.end(), 0ll);
}
int find(int x) {
return pre[x] == x ? x : pre[x] = find(pre[x]);
}
int size(int x) {
return sz[find(x)];
}
bool same(int x, int y) {
return find(x) == find(y);
}
bool merge(int x, int y) {
int fx = find(x), fy = find(y);
if (fx == fy) return false;
if (sz[fx] > sz[fy]) swap(fx, fy);
sz[fy] += sz[fx];
pre[fx] = fy;
return true;//合并成功
}
};
void dfs(int father, int u, int tmp, int dis[]) {
dis[u] = tmp;
for (auto [v, w] : G[u]) {
if (v == father) continue;
dfs(u, v, max(tmp, w), dis);
}
}
void solve() {
cin >> n >> m;
DSU dsu(n);
for (int i = 1, u, v, w; i <= m; i++) {
cin >> u >> v >> w;
e.push_back({u, v, w});
}
std::sort(e.begin(), e.end(), [&](const array<int, 3> a, const array<int, 3> b) {
return a.at(2) < b.at(2);
});
for (auto [u, v, w] : e) {
if (dsu.same(u, v)) continue;
dsu.merge(u, v);
G[u].emplace_back(v, w);
G[v].emplace_back(u, w);
}
dfs(0, 1, 0, dis1);
dfs(0, n, 0, disn);
int ans = INF;
for (auto [u, v, w] : e) { //枚举最大边, 消除同侧影响
int uw = dis1[u], vw = disn[v];
if (w >= max(uw, vw)) ans = min(ans, max(uw, vw) + w);
uw = disn[u], vw = dis1[v];
if (w >= max(uw, vw)) ans = min(ans, max(uw, vw) + w);
}
cout << ans << '\n';
}
signed main() {
std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
Details
answer.code:4:9: fatal error: windows.h: No such file or directory 4 | #include<windows.h> | ^~~~~~~~~~~ compilation terminated.