이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1e5+5;
const ll INF = 1e18;
set<pii> adj[N];
ll dis[N], diss[N];
int n;
void dij(int s){
for(int i = 1; i <= n; ++i)
dis[i] = INF;
priority_queue<pli, vector<pli>, greater<pli>> pq;
pq.push({0, s});
dis[s] = 0;
while(!pq.empty()){
int x = pq.top().ss;
ll val = pq.top().ff;
pq.pop();
if(dis[x] != val)
continue;
tr(it, adj[x]){
int a = it->ff, w = it->ss;
if(umin(dis[a], dis[x]+w))
pq.push({dis[a], a});
}
}
}
int main(){
int m, s, t, u, v;
scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v);
using node = tuple<int, int, int>;
vector<node> A;
for(int i = 1; i <= m; ++i){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
adj[a].insert({b, c});
adj[b].insert({a, c});
A.pb({a, b, c});
}
ll possible = -1;
dij(s);
for(int i = 1; i <= n; ++i)
diss[i] = dis[i];
dij(t);
// dist[i] = dis[i]
// we need to direct all edges
for(auto &i : A){
int a, b, c;
tie(a, b, c) = i;
if(diss[a]+dis[b]+c == diss[t])
adj[a].insert({b, 0});
if(diss[b]+dis[a]+c == diss[t])
adj[b].insert({a, 0});
}
dij(u);
printf("%lld\n", dis[v]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:53:8: warning: unused variable 'possible' [-Wunused-variable]
53 | ll possible = -1;
| ^~~~~~~~
commuter_pass.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d%d%d", &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... |