| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|
| 1306486 | | tnt | Toll (BOI17_toll) | C++20 | | 3093 ms | 4576 KiB |
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#define pb push_back
#define ll long long
#define f first
#define s second
#define sz(v) int(v.size())
#define all(v) v.begin(),v.end()
int mod = 1e9 + 7;
const int N = 50000 + 100,N1 = 5000;
const int inf = 1e9;
vector <pair<int,int>> g[N];
int dp[N];
queue <int> qr;
void solve(){
int k,n,m,q,s,f,u;
cin >> k >> n >> m >> q;
for(int i = 0; i < n; i++) dp[i] = inf;
for(int i = 1; i <= m; i++){
int u,v,w;
cin >> u >> v >> w;
g[u].pb({v,w});
}
while(q--){
cin >> s >> f;
dp[s] = 0;
qr.push(s);
while(!qr.empty()){
u = qr.front();
qr.pop();
for(auto [to,w] : g[u]){
if(to > f || dp[to] <= dp[u] + w) continue;
dp[to] = dp[u] + w;
qr.push(to);
}
}
cout << (dp[f] == inf ? -1 : dp[f]) << '\n';
for(int i = s; i <= f; i++){
dp[i] = inf;
}
}
}
signed main(){
//freopen("time.in", "r", stdin);
//freopen("time.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t1 = 1;
while(t1--){
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |