이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define gcd __gcd
#define siz(v) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
///#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T &a, T b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T &a, T b){if(a > b) return a = b, true; return false;}
const int N = 2e5+5;
const ll MOD = 1e9+7;
const ll inf = 1e18;
int n, m, S, T, U, V, vis[N];
ll d[4][N], dp[2][N], answer;
vector<pair<int,ll>> adj[N];
void Dijk(int source, int id){
for(int i = 1; i <= n; i++){
d[id][i] = (i == source ? 0 : inf);
}
priority_queue<pair<ll,int>> pq;
pq.push(make_pair(0, source));
while(!pq.empty()){
pair<ll,int> t = pq.top(); pq.pop();
if(t.fi > d[id][t.se]) continue;
int x = t.se;
for(pair<int,ll> e : adj[x]){
int v = e.fi; ll w = e.se;
if(d[id][v] > d[id][x] + w){
d[id][v] = d[id][x] + w;
pq.push(make_pair(-d[id][v], v));
}
}
}
return;
}
bool inShortest(int u, int v, ll w){
return d[0][u] + d[1][v] + w == d[0][T];
}
void dfs(int x)
{
dp[0][x] = min(dp[0][x], d[2][x]);
dp[1][x] = min(dp[1][x], d[3][x]);
vis[x] = true;
for(pair<int,ll> e : adj[x]){
int v = e.fi; ll w = e.se;
if(inShortest(x, v, w)){
if(!vis[v]){
dfs(v);
}
dp[0][x] = min(dp[0][x], dp[0][v]);
dp[1][x] = min(dp[1][x], dp[1][v]);
}
}
answer = min(answer, dp[0][x] + d[3][x]);
answer = min(answer, dp[1][x] + d[2][x]);
return;
}
void solve()
{
cin >> n >> m;
cin >> S >> T >> U >> V;
for(int i = 1; i <= m; i++){
int u,v,w; cin >> u >> v >> w;
adj[u].push_back(make_pair(v, w));
adj[v].push_back(make_pair(u, w));
}
Dijk(S, 0), Dijk(T, 1);
Dijk(U, 2), Dijk(V, 3);
for(int i = 1; i <= n; i++){
dp[0][i] = inf;
dp[1][i] = inf;
}
answer = d[2][V];
dfs(S);
cout << answer <<"\n";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
}
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
114 | freopen(name".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:115:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
115 | freopen(name".OUT","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |