이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
struct dsu{
ll n;
vector<ll>sz,par;
dsu(ll n):n(n){
sz.resize(n+1);
par.resize(n+1);
reset();
}
void reset(){
fill(all(sz),1);
iota(all(par),0);
}
ll find(ll x){
if(x==par[x]) return x;
return par[x]=find(par[x]);
}
bool same(ll x,ll y){
x=find(x);
y=find(y);
return x==y;
}
void merge(ll x,ll y){
x=find(x);
y=find(y);
if(x!=y){
if(x<y) swap(x,y);
par[y]=x;
sz[x]+=sz[y];
}
}
};
int main(){
ll n,m;
cin>>n>>m;
vector<pair<ll,ll>>adj[n+5];
vector<array<ll,2>>edge;
for(ll i=1;i<=m;i++){
ll a,b,w;
cin>>a>>b>>w;
edge.pb({a,b});
adj[a].pb({b,w});
adj[b].pb({a,w});
}
ll k;
cin>>k;
ll g[k+5];
ll dist[n+5];
fill(dist,dist+n+1,1e18);
set<pair<ll,ll>>st;
for(ll i=1;i<=k;i++){
cin>>g[i];
st.insert({0,g[i]});
dist[g[i]]=0;
}
while(!st.empty()){
auto [y,i]=*st.begin();
st.erase(st.begin());
if(dist[i]!=y) continue;
for(auto [j,w]:adj[i]){
if(dist[i]+w<dist[j]){
dist[j]=dist[i]+w;
st.insert({dist[j],j});
}
}
}
vector<array<ll,3>>ord;
for(auto [a,b]:edge){
ord.pb({min(dist[a],dist[b]),a,b});
}
sort(rall(ord));
ll q;
cin>>q;
vector<array<ll,3>>ask;
ll s[q+5],t[q+5];
for(ll i=1;i<=q;i++){
cin>>s[i]>>t[i];
ask.pb({0,(ll)1e9,i});
}
ll lg=30;
dsu ds(n);
while(lg--){
ds.reset();
sort(rall(ask));
ll cur=0;
for(ll i=0;i<ask.size();i++){
ll l=ask[i][0],r=ask[i][1],j=ask[i][2];
if(l==r) continue;
ll mid=(l+r+1)/2;
while(cur<m&&ord[cur][0]>=mid){
ds.merge(ord[cur][1],ord[cur][2]);
cur++;
}
if(ds.same(s[j],t[j])){
ask[i]={mid,r,j};
}
else{
ask[i]={l,mid-1,j};
}
}
}
ll ans[q+5];
for(ll i=0;i<q;i++){
ans[ask[i][2]]=ask[i][0];
}
for(ll i=1;i<=q;i++){
cout<<ans[i]<<"\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
plan.cpp: In function 'int main()':
plan.cpp:97:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for(ll i=0;i<ask.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... |