#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 50005
#define INF 0x3f3f3f3f
#define MOD 1000000007LL
vector<pair<int, int> > adj[N], q[N];
int dis[N], mx[N];
vector<int> tmp;
int ans[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
memset(dis, 0x3f, sizeof dis);
int k, n, m, o;
cin>>k>>n>>m>>o;
while(m--){
int a, b, t;
cin>>a>>b>>t;
adj[a].push_back({b, t});
}
for(int i = 1; i <= o; ++i){
int s, e;
cin>>s>>e;
mx[s] = max(mx[s], e);
q[s].push_back({e, i});
}
for(int i = 0; i < n; ++i){
if(mx[i] < i)
continue;
dis[i] = 0;
for(int j = i; j < mx[i]; ++j){
if(dis[j] == INF)continue;
for(auto& x : adj[j])
if(x.ff <= mx[i])
dis[x.ff] = min(dis[j] + x.ss, dis[x.ff]);
}
for(auto& x : q[i])
ans[x.ss] = (dis[x.ff] == INF ? -1 : dis[x.ff]);
for(int j = i; j <= mx[i]; ++j)
dis[j] = INF;
}
for(int i = 1; i <= o; ++i)
cout<<ans[i]<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3026 ms |
5880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
6392 KB |
Output is correct |
2 |
Correct |
4 ms |
2936 KB |
Output is correct |
3 |
Correct |
4 ms |
2936 KB |
Output is correct |
4 |
Correct |
4 ms |
2936 KB |
Output is correct |
5 |
Correct |
4 ms |
2936 KB |
Output is correct |
6 |
Correct |
4 ms |
2936 KB |
Output is correct |
7 |
Correct |
7 ms |
3320 KB |
Output is correct |
8 |
Correct |
8 ms |
3320 KB |
Output is correct |
9 |
Correct |
30 ms |
5624 KB |
Output is correct |
10 |
Correct |
70 ms |
8028 KB |
Output is correct |
11 |
Correct |
53 ms |
6520 KB |
Output is correct |
12 |
Correct |
40 ms |
6008 KB |
Output is correct |
13 |
Correct |
94 ms |
8192 KB |
Output is correct |
14 |
Correct |
46 ms |
6264 KB |
Output is correct |
15 |
Correct |
41 ms |
5496 KB |
Output is correct |
16 |
Correct |
38 ms |
5556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2936 KB |
Output is correct |
2 |
Correct |
5 ms |
2936 KB |
Output is correct |
3 |
Correct |
4 ms |
2936 KB |
Output is correct |
4 |
Correct |
4 ms |
2936 KB |
Output is correct |
5 |
Correct |
4 ms |
2936 KB |
Output is correct |
6 |
Correct |
5 ms |
2936 KB |
Output is correct |
7 |
Correct |
5 ms |
2936 KB |
Output is correct |
8 |
Correct |
7 ms |
3064 KB |
Output is correct |
9 |
Correct |
6 ms |
3068 KB |
Output is correct |
10 |
Correct |
33 ms |
5368 KB |
Output is correct |
11 |
Correct |
102 ms |
6188 KB |
Output is correct |
12 |
Correct |
125 ms |
7672 KB |
Output is correct |
13 |
Correct |
134 ms |
8184 KB |
Output is correct |
14 |
Correct |
125 ms |
6976 KB |
Output is correct |
15 |
Correct |
74 ms |
5496 KB |
Output is correct |
16 |
Correct |
65 ms |
5752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2936 KB |
Output is correct |
2 |
Correct |
5 ms |
2936 KB |
Output is correct |
3 |
Correct |
4 ms |
2936 KB |
Output is correct |
4 |
Correct |
4 ms |
2936 KB |
Output is correct |
5 |
Correct |
4 ms |
2936 KB |
Output is correct |
6 |
Correct |
5 ms |
2936 KB |
Output is correct |
7 |
Correct |
5 ms |
2936 KB |
Output is correct |
8 |
Correct |
7 ms |
3064 KB |
Output is correct |
9 |
Correct |
6 ms |
3068 KB |
Output is correct |
10 |
Correct |
33 ms |
5368 KB |
Output is correct |
11 |
Correct |
102 ms |
6188 KB |
Output is correct |
12 |
Correct |
125 ms |
7672 KB |
Output is correct |
13 |
Correct |
134 ms |
8184 KB |
Output is correct |
14 |
Correct |
125 ms |
6976 KB |
Output is correct |
15 |
Correct |
74 ms |
5496 KB |
Output is correct |
16 |
Correct |
65 ms |
5752 KB |
Output is correct |
17 |
Correct |
1423 ms |
6384 KB |
Output is correct |
18 |
Correct |
4 ms |
2808 KB |
Output is correct |
19 |
Correct |
4 ms |
2936 KB |
Output is correct |
20 |
Correct |
4 ms |
2808 KB |
Output is correct |
21 |
Correct |
4 ms |
2888 KB |
Output is correct |
22 |
Correct |
4 ms |
2936 KB |
Output is correct |
23 |
Correct |
7 ms |
3064 KB |
Output is correct |
24 |
Correct |
10 ms |
3064 KB |
Output is correct |
25 |
Correct |
14 ms |
3064 KB |
Output is correct |
26 |
Correct |
12 ms |
3064 KB |
Output is correct |
27 |
Correct |
134 ms |
5688 KB |
Output is correct |
28 |
Correct |
1635 ms |
7872 KB |
Output is correct |
29 |
Correct |
1730 ms |
8412 KB |
Output is correct |
30 |
Correct |
1040 ms |
7080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3026 ms |
5880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |