Submission #711772

# Submission time Handle Problem Language Result Execution time Memory
711772 2023-03-17T13:26:48 Z BidoTeima Ferries (NOI13_ferries) C++17
17 / 40
475 ms 24732 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 dist[n + 1];
    dist[n] = 0;
    for(int i = 1; i < n; i++){
        dist[i] = 1e18;
    }
    q.push({0, n});
    while(!q.empty()){
        ll d = q.top().first;
        int node = q.top().second;
        q.pop();
        if(d != dist[node])
            continue;
        for(auto& edge : adj_rev[node]){
            int child = edge.first;
            ll cost = edge.second;
            if(d + cost < dist[child]){
                dist[child] = d + cost;
                q.push({dist[child], child});
            }
        }
    }
    for(int i = 1; i <= n; i++){
        sort(child[i].begin(),child[i].end(),[&](int a, int b){
            return (dist[a] < dist[b]); 
        });
        sort(cost[i].begin(),cost[i].end(),[&](int a, int b){
            return a > b;
        }); 
    }
    dist[1] = 0;
    for(int i = 2; i <= n; i++)dist[i] = 1e18;
    q.push({0, 1});
    while(!q.empty()){
        ll d = q.top().first;
        int node = q.top().second;
        q.pop();
        if(d != dist[node])
            continue;
        for(int i = 0; i < (int)child[node].size(); i++){
            int ch = child[node][i];
            int c = cost[node][i];
            if(d + c < dist[ch]){
                dist[ch] = d + c;
                q.push({dist[ch],ch});
            }
        }
    }
    cout<<dist[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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 436 KB Output is correct
3 Correct 20 ms 2796 KB Output is correct
4 Correct 226 ms 24356 KB Output is correct
5 Correct 244 ms 24240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 3 ms 436 KB Output is correct
3 Correct 18 ms 2772 KB Output is correct
4 Correct 102 ms 12260 KB Output is correct
5 Correct 199 ms 19872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 2572 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 475 ms 24732 KB Output isn't correct
2 Halted 0 ms 0 KB -