이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int>>edges;
vector<pair<int,int>>adj[100005];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
int vis[100005];
int dis[100005];
vector<pair<int,pair<int,int>>>op;
vector<int>ord;
int st[100005];
int en[100005];
vector<int>calc[100005];
vector<pair<int,int>>qr;
map<int,int>mp;
int p[100005];
int fp(int a){return p[a]==a?a:p[a]=fp(p[a]);}
void un(int a,int b){p[fp(b)]=fp(a);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m;cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b,c;cin>>a>>b>>c;
        adj[a].push_back({b,c});
        adj[b].push_back({a,c});
        edges.push_back({a,b});
    }
    int k;cin>>k;
    for(int i=1;i<=n;i++)dis[i]=INT_MAX;
    for(int i=0;i<k;i++){
        int g;cin>>g;
        pq.push({0,g});
    }
    while(!pq.empty()){
        int u=pq.top().second;
        int cost=pq.top().first;
        pq.pop();
        if(vis[u])continue;
        dis[u]=cost;
        vis[u]=1;
        for(auto x:adj[u]){
            pq.push({cost+x.second,x.first});
        }
    }
    //for(int i=1;i<=n;i++)cerr<<dis[i]<<" ";
    //cerr<<"\n";
    for(int i=1;i<=n;i++){
        if(!mp[dis[i]])ord.push_back(dis[i]),mp[dis[i]]++;
    }
    sort(ord.begin(),ord.end());
    for(auto x:edges){
        int a=x.first;
        int b=x.second;
        int cst=min(dis[a],dis[b]);
        int id=lower_bound(ord.begin(),ord.end(),cst)-ord.begin();
        op.push_back({id,{a,b}});
    }
    sort(op.begin(),op.end(),greater<pair<int,pair<int,int>>>());
    /*for(auto x:op){
        cerr<<x.first<<" "<<x.second.first<<" "<<x.second.second<<"\n"; 
    }*/
    int q;cin>>q;
    for(int i=1;i<=q;i++){
        int a,b;cin>>a>>b;
        qr.push_back({a,b});
    }
    for(int i=0;i<q;i++){
        st[i]=0,en[i]=ord.size()-1;
    }
    for(int i=0;i<q;i++){
        int m=(st[i]+en[i]+1)/2;
        calc[m].push_back(i);
    }
    //cerr<<"work\n";
    while(1){
        for(int i=1;i<=n;i++)p[i]=i;
        int cur=0;
        for(int i=ord.size()-1;i>0;i--){
            while(cur<op.size()-1&&op[cur].first==i)/*cerr<<"un:"<<op[cur].second.first<<" "<<op[cur].second.second<<"\n",*/un(op[cur].second.first,op[cur].second.second),cur++;
            for(auto x:calc[i]){
                //cerr<<qr[x].first<<" "<<qr[x].second<<" ";
                if(fp(qr[x].first)==fp(qr[x].second))st[x]=i/*,cerr<<"yes\n"*/;
                else en[x]=i-1/*,cerr<<"no\n"*/;
            }
            calc[i].clear();
        }
        int check=0;
        for(int i=0;i<q;i++){
            //cerr<<i<<":"<<st[i]<<" "<<en[i]<<"\n";
            if(st[i]==en[i])continue;
            check=1;
            int m=(st[i]+en[i]+1)/2;
            calc[m].push_back(i);
        }
        if(!check)break;
    }
    for(int i=0;i<q;i++)cout<<ord[st[i]]<<"\n";
}
컴파일 시 표준 에러 (stderr) 메시지
plan.cpp: In function 'int main()':
plan.cpp:79:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             while(cur<op.size()-1&&op[cur].first==i)/*cerr<<"un:"<<op[cur].second.first<<" "<<op[cur].second.second<<"\n",*/un(op[cur].second.first,op[cur].second.second),cur++;
      |                   ~~~^~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |