# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
450603 |
2021-08-03T02:50:40 Z |
czhang2718 |
Toll (BOI17_toll) |
C++14 |
|
308 ms |
28780 KB |
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(x, a) for(auto &x:a)
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define nl '\n'
#define pb push_back
typedef vector<long long> vi;
typedef pair<int, int> pii;
typedef long long ll;
int n, m, k, q;
vector<pii> adj[50001];
vector<pii> radj[50001];
int lx[10001];
int rx[10001];
ll ans[10001];
map<pii, int> edge;
vector<vi> calc(int l, int r, vi &qu){
vector<vi> vec(k*(r-l+1), vi(2*k));
if(r-l==1){
rep(i, 0, k-1){
rep(j, 0, k-1){
int t=edge[{l*k+i, r*k+j}];
vec[i][k+j]=vec[k+j][i]=(t?t:1e18);
}
}
return vec;
}
int m=(l+r)/2;
vi lq, rq;
trav(i, qu){
if(rx[i]/k<m) lq.pb(i);
if(lx[i]/k>m) rq.pb(i);
}
vector<vi> lvec=calc(l, m, lq);
vector<vi> rvec=calc(m, r, rq);
trav(i, qu){
if(rx[i]/k<m || lx[i]/k>m) continue;
if(rx[i]/k==m){
ans[i]=lvec[lx[i]-l*k][k+rx[i]%k]; continue;
}
if(lx[i]/k==m){
ans[i]=rvec[rx[i]-m*k][lx[i]%k]; continue;
}
ans[i]=1e18;
rep(j, 0, k-1){
ans[i]=min(ans[i], lvec[lx[i]-l*k][k+j]+rvec[rx[i]-m*k][j]);
}
}
rep(i, l*k, m*k+k-1){
rep(j, 0, k-1){
vec[i-l*k][j]=lvec[i-l*k][j];
}
}
rep(i, m*k, r*k+k-1){
rep(j, k, 2*k-1){
vec[i-l*k][j]=rvec[i-m*k][k];
}
}
rep(i, (m+1)*k, r*k+k-1){
rep(j, l*k, l*k+k-1){
vec[i-l*k][j-l*k]=1e9;
trav(p, radj[i]) vec[i-l*k][j-l*k]=min(vec[i-l*k][j-l*k], vec[p.f-l*k][j-l*k]+p.s);
}
}
for(int i=m*k-1; i>=l*k; i--){
rep(j, r*k, r*k+k-1){
vec[i-l*k][j-r*k+k]=1e18;
trav(p, adj[i]) vec[i-l*k][j-r*k+k]=min(vec[i-l*k][j-r*k],vec[p.f-l*k][j-r*k+k]+p.s);
}
}
return vec;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin >> k >> n >> m >> q;
rep(i, 1, m){
int a, b, t; cin >> a >> b >> t;
adj[a].pb({b, t});
radj[b].pb({a, t});
edge[{a, b}]=edge[{b, a}]=t;
}
vi qu;
rep(i, 1, q){
cin >> lx[i] >> rx[i];
qu.pb(i);
}
calc(0, (n-1)/k, qu);
rep(i, 1, q) cout << (ans[i]==1e18?-1:ans[i]) << nl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
172 ms |
20488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
308 ms |
28780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
172 ms |
20488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |