이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define taskname "A"
#define pb push_back
#define mp make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,int> lli;
const int maxn = 1e5 + 5;
const ll inf = (ll)1e18;
ll d[4][maxn];
vector<ii> adj[maxn];
void dij(int start , ll d[]){
priority_queue<lli,vector<lli>,greater<lli>> pq;
fill_n(d , maxn , inf);
pq.push(mp(0ll,start));
d[start] = 0;
while(!pq.empty()){
auto u = pq.top();pq.pop();
if(d[u.second] != u.first)continue;
for(ii c : adj[u.second]){
if(d[c.first] > u.first + c.second){
d[c.first] = u.first + c.second;
pq.push(mp(d[c.first],c.first));
}
}
}
}
ll dp[maxn][3];
int n , m , s , t , u , v;
void DFS(int u){
// cout << u << endl;
if(dp[u][0] != inf)return;
cerr << u << " ";
dp[u][0] = min(dp[u][0] , d[0][u]);
dp[u][1] = min(dp[u][1] , d[1][u]);
dp[u][2] = d[0][u] + d[1][u];
for(ii c : adj[u]){
if(d[2][u] + c.second + d[3][c.first] == d[2][t]){
DFS(c.first);
dp[u][2] = min(dp[u][2] , min(dp[u][0],dp[c.first][0]) + dp[u][1]);
dp[u][2] = min(dp[u][2] , dp[u][0] + min(dp[u][1],dp[c.first][1]));
dp[u][2] = min(dp[u][2] , dp[c.first][2]);
}
}
for(ii c : adj[u]){
if(d[2][u] + c.second + d[3][c.first] == d[2][t]){
dp[u][0] = min(dp[u][0],dp[c.first][0]);
dp[u][1] = min(dp[u][1],dp[c.first][1]);
}
}
}
void enter(){
cin >> n >> m;
cin >> s >> t >> u >> v;
for(int i = 1 ; i <= m ; ++i){
int u , v , c;cin >> u >> v >> c;
adj[u].pb(mp(v,c));
adj[v].pb(mp(u,c));
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP", "r",stdin);
freopen(taskname".OUT", "w",stdout);
}
enter();
dij(u , d[0]);
dij(v , d[1]);
dij(s , d[2]);
dij(t , d[3]);
fill_n(&dp[0][0],maxn*3,inf);
DFS(s);
cout << min(dp[s][2],d[0][v]);
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:80:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(taskname".INP", "r",stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:81:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(taskname".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... |