2 条题解

  • 1
    @ 2025-5-31 8:23:17

    very easy!!!阿妈特拉斯!!!

    • 0
      @ 2025-5-31 8:22:40

      #include<bits/stdc++.h> using namespace std; #define INF 1e9 int dijkstra(int n,int s,int t,vector<vector<pair<int,int>>>&adj) { vectormaxx(n+1,INF); priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq; maxx[s]=0; pq.push({0,s}); while(!pq.empty()){ int mmax=pq.top().first; int u=pq.top().second; pq.pop(); if(u==t){ return mmax; } if(mmax>maxx[u]){ continue; } for(auto&edge:adj[u]){ int v=edge.first; int w=edge.second; int maax=max(mmax,w); if(maax<maxx[v]){ maxx[v]=maax; pq.push({maax,v}); } } } return maxx[t]; } struct Edge { int u,v,w; bool operator<(const Edge&other)const{ return w<other.w; } }; vectorparent; int find(int u) { if(parent[u]!=u){ parent[u]=find(parent[u]); } return parent[u]; } void unite(int u,int v) { u=find(u); v=find(v); if(u!=v){ parent[v]=u; } } int kruskal(int n,int s,int t,vector&edges) { sort(edges.begin(),edges.end()); parent.resize(n+1); for(int i=1;i<=n;i++){ parent[i]=i; } for(auto&edge:edges){ unite(edge.u,edge.v); if(find(s)==find(t)){ return edge.w; } } return -1; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,m,s,t; cin>>n>>m>>s>>t; vector<vector<pair<int,int>>>adj(n+1); vectoredges; for(int i=1;i<=m;i++){ int u,v,w; cin>>u>>v>>w; adj[u].emplace_back(v,w); adj[v].emplace_back(u,w); edges.push_back({u,v,w}); } int ans=dijkstra(n,s,t,adj); cout<<ans<<endl; return 0; }

      • 1

      信息

      ID
      2752
      时间
      1000ms
      内存
      256MiB
      难度
      8
      标签
      递交数
      13
      已通过
      7
      上传者