이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// cre: Nguyen Ngoc Hung - Train VOI 2024
#include<bits/stdc++.h>
using namespace std;
#define __nnhzzz__ signed main()
#define BIT(i,j) ((i>>j)&1LL)
#define MASK(i) (1LL<<i)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define pii pair<int,int>
#define vpii vector<pii>
#define REP(i,a,b) for(int i = (a); i<=(b); ++i)
#define REPD(i,a,b) for(int i = (a); i>=(b); --i)
#define REPDIS(i,a,b,c) for(int i = (a); i<=(b); i+=c)
#define int ll
//-------------------------------------------------------------//
const int oo = 1e16,LOG = 20,MAXN = 1e5+7,N = 1e2+3;
const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353;
//-------------------------------------------------------------//
template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;}
/*
----------------------------------------------------------------
END OF TEMPLATE
----------------------------------------------------------------
Nguyen Ngoc Hung - nnhzzz
Training for VOI24 gold medal
----------------------------------------------------------------
*/
vpii adj[MAXN];
void dijkstra(int s, int* dis){
priority_queue<pii,vpii,greater<pii>> heap;
dis[s] = 0; heap.emplace(0,s);
while(SZ(heap)!=0){
auto [w1,u] = heap.top(); heap.pop();
if(dis[u]!=w1) continue;
for(auto [v,w]:adj[u]){
if(mini(dis[v],dis[u]+w)){
heap.emplace(dis[v],v);
}
}
}
}
int dp[3][MAXN],dis[3][MAXN];
int dfs(int u){
if(dp[0][u]!=oo){
return oo;
}
int res = oo;
REP(i,0,1) dp[i][u] = dis[i][u];
for(auto [v,w]:adj[u]){
if(dis[2][v]==dis[2][u]-w){
mini(res,dfs(v));
mini(dp[0][u],dp[0][v]);
mini(dp[1][u],dp[1][v]);
}
}
mini(res,min(dp[0][u]+dis[1][u],dp[1][u]+dis[0][u]));
return res;
}
void solve(){
int n,m,S,T,U,V; cin >> n >> m >> S >> T >> U >> V;
REP(i,1,m){
int u,v,w; cin >> u >> v >> w;
adj[u].emplace_back(v,w);
adj[v].emplace_back(u,w);
}
REP(i,0,2) REP(j,0,n) dp[i][j] = dis[i][j] = oo;
dijkstra(U,dis[0]);
dijkstra(V,dis[1]);
dijkstra(S,dis[2]);
int res = dis[0][V];
// cerr << res;
mini(res,dfs(T));
cout << res;
}
__nnhzzz__{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "test"
if(fopen(name".inp","r")){
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
#define name1 "nnhzzz"
if(fopen(name1".inp","r")){
freopen(name1".inp","r",stdin);
freopen(name1".out","w",stdout);
}
int test = 1;
while(test--){
solve();
}
cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'void dijkstra(long long int, long long int*)':
commuter_pass.cpp:48:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
48 | auto [w1,u] = heap.top(); heap.pop();
| ^
commuter_pass.cpp:50:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
50 | for(auto [v,w]:adj[u]){
| ^
commuter_pass.cpp: In function 'long long int dfs(long long int)':
commuter_pass.cpp:66:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
66 | for(auto [v,w]:adj[u]){
| ^
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
100 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | freopen(name1".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | freopen(name1".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... |