Submission #874227

# Submission time Handle Problem Language Result Execution time Memory
874227 2023-11-16T13:07:12 Z NoLove Toll (BOI17_toll) C++14
0 / 100
3000 ms 7160 KB
/**
 *    author : Lăng Trọng Đạt
 *    created: 16-11-2023 
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int int64_t
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;

const int MAXN = 5e4 + 5;
int g[MAXN];
vector<pii> adj[MAXN];
int k, n, m, o, a, b, t;

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("hi.inp", "r")) {
        freopen("hi.inp", "r", stdin);
//        freopen("hi.out", "w", stdout);
    } 

    cin >> k >> n >> m >> o;
    for (int i = 0; i < m; i++) {
        cin >> a >> b >> t;
        adj[a].pb(mp(b, t));
    }

    while (cin >> a >> b) {
        priority_queue<pii, vector<pii>, greater<pii>> q;
        map<int, int> mp;
        q.push({a, 0});
        while (!q.empty()) {
            int v = q.top().f, d = q.top().s;
            q.pop();
            if (d != mp[v]) continue;
            // db(v, d)
            if (v == b) {
                cout << d << "\n";
                goto cnt;
            }
            for (pii p : adj[v]) {
                if (p.f > b) break;
                if (mp.count(p.f)) mp[p.f] = min(mp[p.f], d + p.s);
                else mp[p.f] = d + p.s;
                q.push({p.f, d + p.s});
            }
        }
        cout << "-1\n";
        cnt:;
    }
}

Compilation message

toll.cpp: In function 'int32_t main()':
toll.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen("hi.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 3026 ms 7160 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3017 ms 6992 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Incorrect 1 ms 1628 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Incorrect 1 ms 1628 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3026 ms 7160 KB Time limit exceeded
2 Halted 0 ms 0 KB -