/**
* 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;
q.push({a, 0});
while (!q.empty()) {
int v = q.top().f, d = q.top().s;
q.pop();
db(v, d)
if (v == b) {
cout << d << "\n";
goto cnt;
}
for (pii p : adj[v]) {
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3035 ms |
4384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3040 ms |
268532 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
2 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1632 KB |
Output is correct |
7 |
Execution timed out |
3108 ms |
264260 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
2 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1632 KB |
Output is correct |
7 |
Execution timed out |
3108 ms |
264260 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3035 ms |
4384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |