#include<bits/stdc++.h>
#include<escape_route.h>
typedef long long ll;
using namespace std;
void init(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
const int mx = 100;
const ll inf = 1e18;
vector<vl> graph[mx];
vector<vl> queries[mx];
bool vis[mx];
ll s;
int n, m, q;
ll ans[mx];
void solve(int st, int target, ll t){
priority_queue<pll, vector<pll>, greater<pll>> pq;
pq.push({t, st});
memset(vis, 0, sizeof vis);
for(int i = 0; i < n;i++){
ans[i] = inf;
}
ans[st] = t;
while(!pq.empty()){
int node = pq.top().ss;
ll tm = pq.top().ff;
pq.pop();
if(vis[node])continue;
vis[node] = 1;
for(vl adj : graph[node]){
ll nxt = tm + adj[1];
if(adj[1] > adj[2])continue;
ll o = nxt % s;
if((nxt/s) > (tm/s) || o > adj[2]){
nxt = (tm / s + 1) * s + adj[1];
}
ans[adj[0]] = min(ans[adj[0]], nxt);
pq.push({ans[adj[0]], adj[0]});
}
}
//cout << ans[2] << endl;
}
std::vector<long long> calculate_necessary_time(
int N, int M, long long S, int Q, std::vector<int> A, std::vector<int> B,
std::vector<long long> L, std::vector<long long> C, std::vector<int> U,
std::vector<int> V, std::vector<long long> T){
n = N, m = M, s = S, q = Q;
for(int i = 0; i < m;i++){
graph[A[i]].pb({B[i], L[i], C[i]});
graph[B[i]].pb({A[i], L[i], C[i]});
}
vl res;
for(int i = 0; i < q;i++){
solve(U[i], V[i], T[i]);
res.pb(ans[V[i]] - T[i]);
}
return res;
}
Compilation message
escape_route.cpp: In function 'void init()':
escape_route.cpp:9:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
escape_route.cpp:11:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
64980 KB |
Output is correct |
2 |
Correct |
58 ms |
64968 KB |
Output is correct |
3 |
Correct |
187 ms |
65108 KB |
Output is correct |
4 |
Correct |
21 ms |
65044 KB |
Output is correct |
5 |
Correct |
165 ms |
65028 KB |
Output is correct |
6 |
Correct |
25 ms |
64980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
9084 ms |
111996 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
64980 KB |
Output is correct |
2 |
Correct |
58 ms |
64968 KB |
Output is correct |
3 |
Correct |
187 ms |
65108 KB |
Output is correct |
4 |
Correct |
21 ms |
65044 KB |
Output is correct |
5 |
Correct |
165 ms |
65028 KB |
Output is correct |
6 |
Correct |
25 ms |
64980 KB |
Output is correct |
7 |
Execution timed out |
9084 ms |
111996 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
64980 KB |
Output is correct |
2 |
Correct |
58 ms |
64968 KB |
Output is correct |
3 |
Correct |
187 ms |
65108 KB |
Output is correct |
4 |
Correct |
21 ms |
65044 KB |
Output is correct |
5 |
Correct |
165 ms |
65028 KB |
Output is correct |
6 |
Correct |
25 ms |
64980 KB |
Output is correct |
7 |
Execution timed out |
9084 ms |
111996 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
64980 KB |
Output is correct |
2 |
Correct |
58 ms |
64968 KB |
Output is correct |
3 |
Correct |
187 ms |
65108 KB |
Output is correct |
4 |
Correct |
21 ms |
65044 KB |
Output is correct |
5 |
Correct |
165 ms |
65028 KB |
Output is correct |
6 |
Correct |
25 ms |
64980 KB |
Output is correct |
7 |
Execution timed out |
9084 ms |
111996 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |