//1L1YA
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#define ll long long
#define Pb push_back
#define dokme(x) cout << x << endl, exit(0)
#define pii pair<int,int>
#define F first
#define S second
#define endl '\n'
#define sep ' '
#define all(x) x.begin(),x.end()
#define FastIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lc id<<1
#define rc lc|1
const ll mod=1e9+7;
const ll oo=4e18;
const int N=5e4+23;
const int lg=23;
int n,m,k,q,d[N];
vector<pii> adj[N];
int main(){
FastIO
cin >> k >> n >> m >> q;
for(int i=1;i<=m;i++){
int u,v,w;
cin >> u >> v >> w;
adj[v].Pb({u,w});
}
while(q--){
int u,v;
cin >> u >> v;
for(int i=0;i<2*k;i++)
if(u-i>=0)
d[u-i]=mod;
d[u]=0;
for(int i=u+1;i<=v;i++){
d[i]=mod;
for(auto w: adj[i])
d[i]=min(d[i],d[w.F]+w.S);
}
if(d[v]==mod)
cout << -1 << endl;
else
cout << d[v] << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
745 ms |
4292 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
1 ms |
1636 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
3 ms |
1880 KB |
Output is correct |
6 |
Correct |
2 ms |
1648 KB |
Output is correct |
7 |
Correct |
3 ms |
1624 KB |
Output is correct |
8 |
Correct |
759 ms |
4296 KB |
Output is correct |
9 |
Correct |
764 ms |
4192 KB |
Output is correct |
10 |
Correct |
123 ms |
1928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1493 ms |
5012 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1624 KB |
Output is correct |
7 |
Correct |
24 ms |
1764 KB |
Output is correct |
8 |
Correct |
18 ms |
1624 KB |
Output is correct |
9 |
Correct |
1066 ms |
4272 KB |
Output is correct |
10 |
Correct |
2246 ms |
6604 KB |
Output is correct |
11 |
Correct |
1452 ms |
5284 KB |
Output is correct |
12 |
Correct |
1966 ms |
4576 KB |
Output is correct |
13 |
Correct |
586 ms |
6876 KB |
Output is correct |
14 |
Correct |
370 ms |
4964 KB |
Output is correct |
15 |
Correct |
434 ms |
4184 KB |
Output is correct |
16 |
Correct |
431 ms |
4176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1628 KB |
Output is correct |
7 |
Correct |
1 ms |
1692 KB |
Output is correct |
8 |
Correct |
3 ms |
1628 KB |
Output is correct |
9 |
Correct |
2 ms |
1648 KB |
Output is correct |
10 |
Correct |
30 ms |
4080 KB |
Output is correct |
11 |
Correct |
35 ms |
4688 KB |
Output is correct |
12 |
Correct |
45 ms |
6252 KB |
Output is correct |
13 |
Correct |
47 ms |
6748 KB |
Output is correct |
14 |
Correct |
41 ms |
5464 KB |
Output is correct |
15 |
Correct |
27 ms |
4184 KB |
Output is correct |
16 |
Correct |
26 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1628 KB |
Output is correct |
7 |
Correct |
1 ms |
1692 KB |
Output is correct |
8 |
Correct |
3 ms |
1628 KB |
Output is correct |
9 |
Correct |
2 ms |
1648 KB |
Output is correct |
10 |
Correct |
30 ms |
4080 KB |
Output is correct |
11 |
Correct |
35 ms |
4688 KB |
Output is correct |
12 |
Correct |
45 ms |
6252 KB |
Output is correct |
13 |
Correct |
47 ms |
6748 KB |
Output is correct |
14 |
Correct |
41 ms |
5464 KB |
Output is correct |
15 |
Correct |
27 ms |
4184 KB |
Output is correct |
16 |
Correct |
26 ms |
4444 KB |
Output is correct |
17 |
Correct |
306 ms |
4948 KB |
Output is correct |
18 |
Correct |
1 ms |
1624 KB |
Output is correct |
19 |
Correct |
1 ms |
1628 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
21 |
Correct |
1 ms |
1880 KB |
Output is correct |
22 |
Correct |
1 ms |
1884 KB |
Output is correct |
23 |
Correct |
5 ms |
1712 KB |
Output is correct |
24 |
Correct |
5 ms |
1624 KB |
Output is correct |
25 |
Correct |
12 ms |
1812 KB |
Output is correct |
26 |
Correct |
6 ms |
1624 KB |
Output is correct |
27 |
Correct |
227 ms |
4208 KB |
Output is correct |
28 |
Correct |
428 ms |
6740 KB |
Output is correct |
29 |
Correct |
396 ms |
6996 KB |
Output is correct |
30 |
Correct |
501 ms |
5744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
745 ms |
4292 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
1 ms |
1636 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
3 ms |
1880 KB |
Output is correct |
6 |
Correct |
2 ms |
1648 KB |
Output is correct |
7 |
Correct |
3 ms |
1624 KB |
Output is correct |
8 |
Correct |
759 ms |
4296 KB |
Output is correct |
9 |
Correct |
764 ms |
4192 KB |
Output is correct |
10 |
Correct |
123 ms |
1928 KB |
Output is correct |
11 |
Correct |
1493 ms |
5012 KB |
Output is correct |
12 |
Correct |
1 ms |
1628 KB |
Output is correct |
13 |
Correct |
1 ms |
1628 KB |
Output is correct |
14 |
Correct |
1 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1628 KB |
Output is correct |
16 |
Correct |
1 ms |
1624 KB |
Output is correct |
17 |
Correct |
24 ms |
1764 KB |
Output is correct |
18 |
Correct |
18 ms |
1624 KB |
Output is correct |
19 |
Correct |
1066 ms |
4272 KB |
Output is correct |
20 |
Correct |
2246 ms |
6604 KB |
Output is correct |
21 |
Correct |
1452 ms |
5284 KB |
Output is correct |
22 |
Correct |
1966 ms |
4576 KB |
Output is correct |
23 |
Correct |
586 ms |
6876 KB |
Output is correct |
24 |
Correct |
370 ms |
4964 KB |
Output is correct |
25 |
Correct |
434 ms |
4184 KB |
Output is correct |
26 |
Correct |
431 ms |
4176 KB |
Output is correct |
27 |
Correct |
1 ms |
1628 KB |
Output is correct |
28 |
Correct |
1 ms |
1628 KB |
Output is correct |
29 |
Correct |
1 ms |
1628 KB |
Output is correct |
30 |
Correct |
1 ms |
1628 KB |
Output is correct |
31 |
Correct |
1 ms |
1628 KB |
Output is correct |
32 |
Correct |
1 ms |
1628 KB |
Output is correct |
33 |
Correct |
1 ms |
1692 KB |
Output is correct |
34 |
Correct |
3 ms |
1628 KB |
Output is correct |
35 |
Correct |
2 ms |
1648 KB |
Output is correct |
36 |
Correct |
30 ms |
4080 KB |
Output is correct |
37 |
Correct |
35 ms |
4688 KB |
Output is correct |
38 |
Correct |
45 ms |
6252 KB |
Output is correct |
39 |
Correct |
47 ms |
6748 KB |
Output is correct |
40 |
Correct |
41 ms |
5464 KB |
Output is correct |
41 |
Correct |
27 ms |
4184 KB |
Output is correct |
42 |
Correct |
26 ms |
4444 KB |
Output is correct |
43 |
Correct |
306 ms |
4948 KB |
Output is correct |
44 |
Correct |
1 ms |
1624 KB |
Output is correct |
45 |
Correct |
1 ms |
1628 KB |
Output is correct |
46 |
Correct |
1 ms |
1628 KB |
Output is correct |
47 |
Correct |
1 ms |
1880 KB |
Output is correct |
48 |
Correct |
1 ms |
1884 KB |
Output is correct |
49 |
Correct |
5 ms |
1712 KB |
Output is correct |
50 |
Correct |
5 ms |
1624 KB |
Output is correct |
51 |
Correct |
12 ms |
1812 KB |
Output is correct |
52 |
Correct |
6 ms |
1624 KB |
Output is correct |
53 |
Correct |
227 ms |
4208 KB |
Output is correct |
54 |
Correct |
428 ms |
6740 KB |
Output is correct |
55 |
Correct |
396 ms |
6996 KB |
Output is correct |
56 |
Correct |
501 ms |
5744 KB |
Output is correct |
57 |
Correct |
1477 ms |
7860 KB |
Output is correct |
58 |
Correct |
771 ms |
4300 KB |
Output is correct |
59 |
Correct |
941 ms |
5460 KB |
Output is correct |