이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define INF LLONG_MAX/2
#define sacnf scanf
#define scnf scanf
#define scnaf scanf
#define CRLF <<'\n';
#define ALL(v) v.begin,v.end()
#define SIZE(v) (int)v.size()
#define PRPAIR(x) x.first << x.second
#define DEBUG(x) do { std::cerr <<(x)<<'\n'; } while (0)
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef pair<int,ii> pip;
typedef vector<ll> vi;
#define N 100005
#define M 200005
int n,m,s,t,u,v;
vi ds,dt,du,dv;
vector<ii> adj[N];
void sssp(int i,vi &dist){
dist.assign(n,INF);
dist[i] = 0;
priority_queue<ii,vector<ii>,greater<ii>> q;
q.push({0,i});
while(!q.empty()){
ii a=q.top(); q.pop();
ll d = a.first, u = a.second;
if (dist[u] < d)
continue;
for(auto v: adj[u]){
if (dist[u] + v.second < dist[v.first]){
dist[v.first] = dist[u] + v.second;
q.push({dist[v.first],v.first});
}
}
}
}
bitset<N> onsp,vis;
vi g[N],g2[N];
void bs(int i){
onsp[i] = 1;
vis[i] = 1;
if (i == s)
return;
for(auto v: adj[i]){
if (!vis[v.first] && ds[v.first] + v.second == ds[i]){
g2[i].push_back(v.first);
g[v.first].push_back(i);
bs(v.first);
}
}
}
ll dfs(ll utosp,int i){
if (i == t)
return du[v];
vis[i] = 1;
ll minv=utosp+dv[i];
for(auto v: g[i]){
if (!vis[v] && onsp[v])
minv = min(dfs(min(utosp,du[v]),v),minv);
}
return minv;
}
ll dfs2(ll utosp,int i){
if (i == s)
return du[v];
vis[i] = 1;
ll minv=utosp+dv[i];
for(auto v: g2[i]){
if (!vis[v] && onsp[v])
minv = min(dfs2(min(utosp,du[v]),v),minv);
}
return minv;
}
int main(){
scanf("%d%d%d%d%d%d",&n,&m,&s,&t,&u,&v);
s--,t--,u--,v--;
rep(i,0,m){
ll a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
a--,b--;
adj[a].emplace_back(b,c);
adj[b].emplace_back(a,c);
}
sssp(s,ds),sssp(t,dt),sssp(u,du),sssp(v,dv);
rep(i,0,n){
//cout << i+1 << ' ' << ds[i] << '\n';
}
vis.reset();
bs(t);
rep(i,0,n){
//cout << i+1 << " " << onsp[i] << '\n';
}
vis.reset();
ll ans = dfs(du[s],s);
vis.reset();
ans = min(ans,dfs2(du[t],t));
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:89:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
89 | scanf("%d%d%d%d%d%d",&n,&m,&s,&t,&u,&v);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
94 | scanf("%lld%lld%lld",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |