QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#687053#7883. Takeout Deliveringqikala7777WA 2ms7752kbC++232.0kb2024-10-29 16:55:092024-10-29 16:55:10

Judging History

你现在查看的是最新测评结果

  • [2024-10-29 16:55:10]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7752kb
  • [2024-10-29 16:55:09]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef tuple<int,LL,LL> TPL;
typedef pair<LL,LL> PII;
const int N=1e6+7,inf=0x3f3f3f3f;const LL Linf=0x3f3f3f3f3f3f3f3fLL;
LL qsm(LL a,LL b,LL p){LL res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
LL lowbit(LL x){return x&-x;}
int n,m;
vector<PII> G[N];
struct{
    int u,v;
    LL w;
}seg[N];
int p[N];
int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
LL dis1[N],distn[N],res;
void dfs(int u,int fa,LL dis[]){
    for(auto [v,w]:G[u]){
        if(v==fa)continue;
        dis[v]=max(dis[u],w);
        dfs(v,u,dis);
    }
}
bool check(int u,int v){
    if(find(u)==find(1)&&find(v)==find(n))return true;
    if(find(u)==find(n)&&find(v)==find(1))return true;
}
void solve(){
    cin>>n>>m;
    res=Linf;
    for(int i=1;i<=n;i++)p[i]=i;
    for(int i=1;i<=m;i++){
        cin>>seg[i].u>>seg[i].v>>seg[i].w;
    }
    sort(seg+1,seg+m+1,[](auto a,auto b){return a.w<b.w;});
    int cnt=0;
    for(int i=1;i<=m;i++){
        int u=seg[i].u,v=seg[i].v;
        if(u==1&&v==n||v==1&&u==n){
            res=min(res,seg[i].w);
        }
        int pu=find(u),pv=find(v);
        if(pu==pv)continue;
        if(check(u,v)){
            cnt=i;
            break;
        }
        p[pu]=pv;
        G[u].push_back({v,seg[i].w});
        G[v].push_back({u,seg[i].w});
    }
    dfs(1,0,dis1);
    dfs(n,0,distn);
    for(int i=cnt;i<=m;i++){
        LL u=seg[i].u,v=seg[i].v,w=seg[i].w;
        if(check(u,v)){
            array<LL,3> a={dis1[u],distn[v],w};
            sort(a.begin(),a.end());
            if(a[2]!=0&&a[1]!=0)res=min(res,a[2]+a[1]);
            a={dis1[v],distn[u],w};
            sort(a.begin(),a.end());
            if(a[2]!=0&&a[1]!=0)res=min(res,a[2]+a[1]);
        }
    }
    cout<<res<<endl;
}
int main(){
   IOS
   int T=1;
   //cin>>T;
    while(T--)solve();

    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 7752kb

input:

4 6
1 2 2
1 3 4
1 4 7
2 3 1
2 4 3
3 4 9

output:

4557430888798830399

result:

wrong answer 1st numbers differ - expected: '5', found: '4557430888798830399'