# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
170984 |
2019-12-26T21:58:38 Z |
Rods |
Toll (BOI17_toll) |
C++14 |
|
3000 ms |
12892 KB |
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ll long long
#define int ll
#define ld long double
#define ii pair<int, int>
#define iii pair<int, ii>
#define vi vector<int>
#define vii vector<ii>
using namespace std;
const int ms = 5e4+100;
const int inf = 1e15;
const int sigma = 8;
const int mlg = 23;
int n, m, k, t, q;
vii g[ms];
int dis[ms][sigma];
int adj[ms];
priority_queue<ii, vector<ii>, greater<ii>> pq;
void dijkstra(int x, int p) {
dis[x][p] = 0;
pq.push(ii(0, x));
while(!pq.empty()) {
ii x = pq.top(); pq.pop();
int u = x.second;
if(x.first > dis[u][p]) continue;
for(auto e : g[u]) {
int v = e.first, w = e.second;
if(dis[u][p]+w < dis[v][p]) {
dis[v][p] = dis[u][p] + w;
pq.push(ii(dis[v][p], v));
}
}
}
}
void is_conected(int a, int b, set<int> &vis){
if(a/k > b/k) return;
vis.insert(a);
for(auto x: g[a]){
if(vis.count(x.x)==0) is_conected(x.x, b, vis);
}
}
void solve(){
for(int i=0; i<ms; i++){
for(int j=0; j<sigma; j++)
dis[i][j] = inf;
}
cin>>k>>n>>m>>q;
int a, b, c;
for(int i=0; i<m; i++){
cin>>a>>b>>c;
adj[b]++;
g[a].pb({b, c});
}
for(int i=0; i<n; i++){
if(adj[i]==0){
// g[n+i%k].pb({i, 0});
}
}
for(int i=0; i<n; i++){
if(dis[i][0]==inf){
dijkstra(i, 0);
}
}
while(q--){
cin>>a>>b;
set<int> aux;
is_conected(a, b, aux);
if(aux.count(b)){
cout<<dis[b][0] - dis[a][0]<<endl;
}else{
cout<<-1<<endl;
}
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3020 ms |
12892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3013 ms |
11128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4600 KB |
Output is correct |
2 |
Incorrect |
5 ms |
4600 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4600 KB |
Output is correct |
2 |
Incorrect |
5 ms |
4600 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3020 ms |
12892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |