QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#735157 | #7883. Takeout Delivering | yld | WA | 158ms | 72608kb | C++20 | 2.1kb | 2024-11-11 17:49:33 | 2024-11-11 17:49:34 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve()
{
int n,m;
cin>>n>>m;
vector<pair<int,int>> e[n+1];
vector<array<int,3>> edge(m+1);
vector<int> fa(n+1);
for(int i=1;i<=n;i++) fa[i]=i;
function<int(int)> getfa=[&](int x)
{
if(x==fa[x]) return x;
return fa[x]=getfa(fa[x]);
};
for(int i=1;i<=m;i++)
{
auto &[w,u,v]=edge[i];
cin>>u>>v>>w;
}
sort(edge.begin()+1,edge.end(),greater<>());
// for(int i=1;i<=m;i++)
// {
// auto [w,u,v]=edge[i];
// cout<<u<<' '<<v<<' '<<w<<endl;
// }
for(int i=1;i<=m;i++)
{
auto [w,u,v]=edge[i];
int fx=getfa(u),fy=getfa(v);
if(fx!=fy)
{
e[u].push_back({v,w});
e[v].push_back({u,w});
fa[fx]=fy;
}
}
// for(int i=1;i<=n;i++)
// for(auto [v,w]:e[i]) cout<<i<<' '<<v<<' '<<w<<endl;
vector<int> pre(n+1),suf(n+1);
function<void(int,int,int)> dfs=[&](int u,int f,int op)
{
// cout<<u<<endl;
for(auto [v,w]:e[u])
{
if(v==f) continue;
if(op==1) pre[v]=max(pre[v],pre[u]+w);
else suf[v]=max(suf[v],suf[u]+w);
dfs(v,u,op);
}
};
dfs(1,0,1);
dfs(n,0,2);
// for(int i=1;i<=n;i++) cout<<pre[i]<<' ';
// cout<<endl;
// for(int i=1;i<=n;i++) cout<<suf[i]<<' ';
// cout<<endl;
auto cal=[&](int u,int v,int w)
{
int max1=0,max2=0;
vector<int> tmp;
tmp.push_back(pre[u]);
tmp.push_back(suf[v]);
tmp.push_back(w);
for(auto x:tmp)
if(x>=max1)
max2=max1,max1=x;
else if(x>=max2) max2=x;
return max1+max2;
};
int ans=1e18;
for(int i=1;i<=m;i++)
{
auto [w,u,v]=edge[i];
int tmp=min(max(pre[u],suf[v]),max(pre[v],suf[u]));
ans=min(tmp+w,ans);
}
cout<<ans<<endl;
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
int t=1;
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3512kb
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: 158ms
memory: 72608kb
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:
74975188371113
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '74975188371113'