# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
711778 | BidoTeima | 페리들 (NOI13_ferries) | C++17 | 452 ms | 22312 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
ID: BidoTeima
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void moo(string filename);
void ACPLS(string str = "")
{
if(str=="NOF")return;
if(str.size() && str != "IIOT")
moo(str);
else if(str != "IIOT"){
#ifndef ONLINE_JUDGE
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
#endif
}
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void moo(string fileName){
freopen((fileName+".in").c_str(),"r",stdin);
freopen((fileName+".out").c_str(),"w",stdout);
}
#define tcccc \
int tttttt/*,subtask*/; \
cin >> tttttt/* >> subtask*/; \
while (tttttt--)/*end
*/
int main()
{
//ACPLS("");
int n,m;
cin>>n>>m;
vector<int>child[n + 1];
vector<int>cost[n + 1];
vector<pair<int,int>>adj_rev[n + 1];
for(int i = 0; i < m; i++){
int a,b,c;
cin>>a>>b>>c;
child[a].push_back(b);
cost[a].push_back(c);
adj_rev[b].push_back({a, c});
}
using _Ty = pair<ll, int>;
priority_queue<_Ty, vector<_Ty>, greater<_Ty>> q;
ll dist1[n + 1];
dist1[n] = 0;
for(int i = 1; i < n; i++){
dist1[i] = 1e18;
}
q.push({0, n});
while(!q.empty()){
ll d = q.top().first;
int node = q.top().second;
q.pop();
if(d != dist1[node])
continue;
for(auto& edge : adj_rev[node]){
int child = edge.first;
ll cost = edge.second;
if(d + cost < dist1[child]){
dist1[child] = d + cost;
q.push({dist1[child], child});
}
}
}
ll dist2[n + 1];
dist2[1] = 0;
for(int i = 2; i <= n; i++)dist2[i] = 1e18;
q.push({0, 1});
while(!q.empty()){
ll d = q.top().first;
int node = q.top().second;
q.pop();
if(d != dist2[node])
continue;
vector<int> v1 = child[node];
vector<int> v2 = cost[node];
sort(v1.begin(), v1.end(), [&](int a, int b){
return dist1[a] < dist1[b];
});
sort(v2.begin(),v2.end(),greater<int>());
for(int i = 0; i < (int)v1.size(); i++){
int ch = v1[i];
int c = v2[i];
if(d + c < dist2[ch]){
dist2[ch] = d + c;
q.push({dist2[ch],ch});
}
}
}
cout<<dist2[n];
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |