답안 #711795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711795 2023-03-17T14:10:33 Z BidoTeima 페리들 (NOI13_ferries) C++17
10 / 40
494 ms 33436 KB
/*
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;
    using _Ty2 = vector<ll>;
    priority_queue<_Ty2, vector<_Ty2>, greater<_Ty2>>pq;
    pq.push({0, 0, 1});
    while(!pq.empty()){
        ll d = pq.top()[0];
        bool b = pq.top()[1];
        int node = pq.top()[2]; 
        pq.pop(); 
        vector<int> v1 = child[node];
        vector<int> v2 = cost[node];
        if(!b){
            sort(v1.begin(), v1.end(), [&](int aa, int bb){
                return dist1[aa] < dist1[bb];
            });
            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;
                pq.push({dist2[ch],!b,ch});
                pq.push({dist2[ch],b,ch});
            }
        }
    }
    cout<<min(dist2[n],dist2[n]);
}   

Compilation message

ferries.cpp: In function 'void ACPLS(std::string)':
ferries.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
ferries.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ferries.cpp: In function 'void moo(std::string)':
ferries.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((fileName+".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ferries.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((fileName+".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 26 ms 3948 KB Output is correct
4 Runtime error 303 ms 33436 KB Memory limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 26 ms 3960 KB Output is correct
4 Correct 165 ms 16956 KB Output is correct
5 Correct 254 ms 20592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 2576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 494 ms 20984 KB Output isn't correct
2 Halted 0 ms 0 KB -