QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#728807 | #7883. Takeout Delivering | ucup-team3474 | WA | 288ms | 55044kb | C++20 | 1.9kb | 2024-11-09 15:59:10 | 2024-11-09 15:59:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int N=1e6+10;
ll n,m,k;
vector<PII> e[N];
// vector<PII> v;
vector<array<int,3>> ed;
vector<array<int,3>> unused;
int p[N];
int find(int x){
if(p[x]!=x) p[x]=find(p[x]);
return p[x];
}
ll d1[N][2],d2[N][2];
void dfs1(int x,int fa){
for(auto [j,w]:e[x]){
if(j==fa) continue;
// d1[j]=max(d1[x],w);
if(w>d1[j][0]){
d1[j][1]=d1[j][0];
d1[j][0]=w;
}else if(w>d1[j][1]){
d1[j][1]=w;
}
dfs1(j,x);
}
}
void dfs2(int x,int fa){
for(auto [j,w]:e[x]){
if(j==fa) continue;
if(w>d2[j][0]){
d2[j][1]=d2[j][0];
d2[j][0]=w;
}else if(w>d2[j][1]){
d2[j][1]=w;
}
dfs2(j,x);
}
}
int ans=1e9;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
int u,v,w;
cin>>u>>v>>w;
ed.push_back({w,u,v});
}
sort(ed.begin(),ed.end());
for(int i=1;i<=n;i++) p[i]=i;
for(auto [w,u,v]:ed){
if(find(u)!=find(v)){
p[find(u)]=find(v);
e[u].push_back({v,w});
e[v].push_back({u,w});
}else{
unused.push_back({w,u,v});
}
}
dfs1(1,-1);
dfs2(n,-1);
ans=d1[n][0]+d1[n][1];
for(auto [w,u,v]:unused){
vector<int> xx;
xx.push_back(w);
xx.push_back(d1[u][0]);
xx.push_back(d1[u][1]);
xx.push_back(d2[v][0]);
xx.push_back(d2[v][1]);
sort(xx.begin(),xx.end(),greater<int>());
ans=min(ans,xx[0]+xx[1]);
xx.clear();
xx.push_back(w);
xx.push_back(d2[u][0]);
xx.push_back(d2[u][1]);
xx.push_back(d1[v][0]);
xx.push_back(d1[v][1]);
sort(xx.begin(),xx.end(),greater<int>());
ans=min(ans,xx[0]+xx[1]);
}
cout<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5604kb
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: 288ms
memory: 55044kb
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:
301109072
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '301109072'