QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#757768 | #7883. Takeout Delivering | surenjamts# | WA | 382ms | 62524kb | C++20 | 3.0kb | 2024-11-17 13:19:21 | 2024-11-17 13:19:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define S second
#define F first
const int N = 3e5 + 5;
vector<pair<int, int>> adj[N];
vector<int> active[N];
vector<tuple<int, int, int>> edges;
vector<bool> vis;
int n, m;
void init(){
cin >> n >> m;
vis.assign(n + 1, 0);
int u, v, w;
for(int i = 0; i < m; i++){
cin >> u >> v >> w;
if(u > v) swap(u, v);
adj[v].emplace_back(u, w);
adj[u].emplace_back(v, w);
edges.emplace_back(w, u, v);
}
}
vector<int> nw;
void dfs(int v){
if(vis[v]) return;
// cout << "irsen :" << v << endl;
vis[v] = true;
nw.push_back(v);
for(auto u: active[v]){
if(vis[u]) continue;
dfs(u);
}
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
init();
sort(edges.begin(), edges.end());
int ans = 2e9 + 5;
set<pair<int, int>> s1, s2;
vector<bool> cnt1(n + 1, 0), cnt2(n + 1, 0);
cnt1[1] = cnt2[n] = true;
vis[1] = vis[n] = true;
int t_mn = 2e9;
for(auto &[u, w] : adj[1]) {
if(u == n) ans = w;
s1.insert({1, u});
}
int ih, baga;
for(auto &[u, _] : adj[n]) s2.insert({u, n});
for(auto &[weigth, u, v] : edges){
nw.clear();
// cout << "cur edge: " << u << " " << v << endl;
active[u].pb(v);
active[v].pb(u);
if(cnt1[u] || cnt1[v]){
dfs(u); dfs(v);
for(auto new_vert : nw){
// cout << "new :" << new_vert << endl;
for(auto &[t, w] : adj[new_vert]){
// cout << "temptrul :" << t << endl;
baga = min(new_vert, t), ih = max(new_vert, t);
if(s2.count({baga, ih})) t_mn = min(t_mn, w);
s1.insert({baga, ih});
}
cnt1[new_vert] = true;
}
}else if(cnt2[u] || cnt2[v]){
dfs(u); dfs(v);
for(auto new_vert : nw){
// cout << "new :" << new_vert << endl;
for(auto &[t, w] : adj[new_vert]){
baga = min(new_vert, t), ih = max(new_vert, t);
// cout << "temptrul :" << t << endl;
if(s1.count({baga, ih})) t_mn = min(t_mn, w);
s2.insert({baga, ih});
}
cnt2[new_vert] = true;
}
}
// cout << "tmin :" << t_mn << endl;
// cout << "cnt1 :\n";
// for(int i = 0; i <=n; i++) if(cnt1[i]) cout << i << " ";
// cout << endl;
// cout << "cnt2 :\n";
// for(int i = 0; i <=n; i++) if(cnt2[i]) cout << i << " ";
// cout << endl;
// cout << endl;
ans = min(weigth + t_mn, ans);
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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: 382ms
memory: 62524kb
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:
-2147475215
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '-2147475215'