이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
using namespace std;
const int mxn=1e5+5;
vector<pii>g[mxn];
int d[mxn],l[mxn],r[mxn];pii ask[mxn];
int pr[mxn];
int get(int r){
return pr[r]==r?r:pr[r]=get(pr[r]);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m;cin>>n>>m;vector<pair<int,pii>>ed;
for(int i=1,a,b,w;i<=m;i++){
cin>>a>>b>>w;g[a].pb({b,w});g[b].pb({a,w});ed.pb({0,{a,b}});
}priority_queue<pii,vector<pii>,greater<pii>>pq;
for(int i=1;i<=n;i++)d[i]=1e9;
int k;cin>>k;
for(int i=1,u;i<=k;i++){
cin>>u;d[u]=0;pq.push({d[u],u});
}
while(!pq.empty()){
auto u=pq.top();pq.pop();
if(u.f>d[u.s])continue;
for(auto v:g[u.s]){
if(d[v.f]>u.f+v.s)d[v.f]=u.f+v.s,pq.push({d[v.f],v.f});
}
}
for(int i=0;i<ed.size();i++)ed[i].f=min(d[ed[i].s.f],d[ed[i].s.s]);
sort(ed.rbegin(),ed.rend());
int q;cin>>q;
for(int i=1;i<=q;i++)cin>>ask[i].f>>ask[i].s,l[i]=1,r[i]=ed.size();
bool done=0;vector<int>qr[(int)ed.size()+1];
while(!done){
done=1;iota(pr,pr+n+1,0);
for(int i=1;i<=q;i++){
if(l[i]==r[i])continue;
done=0;qr[(l[i]+r[i])>>1].pb(i);
}if(done)break;
for(int i=1;i<=ed.size();i++){
pr[get(ed[i-1].s.f)]=pr[get(ed[i-1].s.s)];
for(auto it : qr[i]){
if(get(ask[it].f)==get(ask[it].s))r[it]=i;
else l[it]=i+1;
}qr[i].clear();
}
}
for(int i=1;i<=q;i++)cout<<ed[l[i]-1].f<<'\n';
}
컴파일 시 표준 에러 (stderr) 메시지
plan.cpp: In function 'int main()':
plan.cpp:41:18: 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]
41 | for(int i=0;i<ed.size();i++)ed[i].f=min(d[ed[i].s.f],d[ed[i].s.s]);
| ~^~~~~~~~~~
plan.cpp:52: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]
52 | for(int i=1;i<=ed.size();i++){
| ~^~~~~~~~~~~
# | 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... |