QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#728831#7883. Takeout Deliveringucup-team3474WA 2ms5904kbC++201.9kb2024-11-09 16:01:502024-11-09 16:01:54

Judging History

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

  • [2024-11-09 16:01:54]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5904kb
  • [2024-11-09 16:01:50]
  • 提交

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=2e9+10;

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;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;
}

详细

Test #1:

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

input:

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

output:

3

result:

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