// Dmitry _kun_ Sayutin (2019)
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::cerr;
using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::pair;
using std::make_pair;
using std::tuple;
using std::make_tuple;
using std::get;
using std::min;
using std::abs;
using std::max;
using std::swap;
using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;
#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif
template <typename T>
T input() {
T res;
cin >> res;
LASSERT(cin);
return res;
}
template <typename IT>
void input_seq(IT b, IT e) {
std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}
#define SZ(vec) int((vec).size())
#define ALL(data) data.begin(),data.end()
#define RALL(data) data.rbegin(),data.rend()
#define TYPEMAX(type) std::numeric_limits<type>::max()
#define TYPEMIN(type) std::numeric_limits<type>::min()
struct edge_t {
int to;
int64_t w;
};
void solve() {
int n, m, q, p;
cin >> n >> m >> q >> p;
vector<vector<edge_t>> graph(n);
for (int i = 0; i != m; ++i) {
int v = input<int>() - 1;
int u = input<int>() - 1;
int64_t w = input<int64_t>();
graph[u].push_back(edge_t {v, w});
}
vector<vector<int64_t>> segms(n);
segms[0] = {0};
for (int v = 1; v != n; ++v) {
vector<int64_t> lst;
for (auto u: graph[v])
for (int64_t val: segms[u.to])
lst.push_back(val + u.w);
sort(ALL(lst));
lst.resize(std::unique(ALL(lst)) - lst.begin());
reverse(ALL(lst));
for (int64_t elem: lst) {
while (segms[v].size() >= 2 and p * elem > (p - 1) * segms[v][SZ(segms[v]) - 2])
segms[v].pop_back();
segms[v].push_back(elem);
}
assert(segms[v].size() <= 1500);
}
for (; q != 0; --q) {
int v = input<int>() - 1;
int64_t w = input<int64_t>();
bool ok = false;
for (int64_t len: segms[v])
if (w <= len and len * (p - 1) <= w * p) {
ok = true;
break;
}
cout << (ok ? '1' : '0');
}
cout << "\n";
}
int main() {
std::iostream::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// code here
for (int t = input<int>(); t != 0; --t)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
9 ms |
384 KB |
Output is correct |
13 |
Correct |
8 ms |
384 KB |
Output is correct |
14 |
Correct |
9 ms |
384 KB |
Output is correct |
15 |
Correct |
8 ms |
384 KB |
Output is correct |
16 |
Correct |
7 ms |
384 KB |
Output is correct |
17 |
Correct |
7 ms |
384 KB |
Output is correct |
18 |
Correct |
8 ms |
384 KB |
Output is correct |
19 |
Correct |
8 ms |
384 KB |
Output is correct |
20 |
Correct |
8 ms |
384 KB |
Output is correct |
21 |
Correct |
8 ms |
384 KB |
Output is correct |
22 |
Correct |
7 ms |
384 KB |
Output is correct |
23 |
Correct |
6 ms |
384 KB |
Output is correct |
24 |
Correct |
6 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
6 ms |
308 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
6 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
12 ms |
896 KB |
Output is correct |
12 |
Correct |
4 ms |
768 KB |
Output is correct |
13 |
Correct |
7 ms |
768 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
768 KB |
Output is correct |
23 |
Correct |
5 ms |
768 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
3 ms |
384 KB |
Output is correct |
30 |
Correct |
3 ms |
384 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
39 ms |
4980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
478 ms |
34604 KB |
Output is correct |
3 |
Correct |
366 ms |
7600 KB |
Output is correct |
4 |
Correct |
351 ms |
3988 KB |
Output is correct |
5 |
Correct |
300 ms |
1112 KB |
Output is correct |
6 |
Correct |
370 ms |
11388 KB |
Output is correct |
7 |
Correct |
382 ms |
6352 KB |
Output is correct |
8 |
Correct |
390 ms |
11740 KB |
Output is correct |
9 |
Correct |
341 ms |
6144 KB |
Output is correct |
10 |
Correct |
328 ms |
11356 KB |
Output is correct |
11 |
Correct |
313 ms |
5976 KB |
Output is correct |
12 |
Correct |
95 ms |
512 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
8 ms |
384 KB |
Output is correct |
15 |
Correct |
13 ms |
384 KB |
Output is correct |
16 |
Correct |
10 ms |
384 KB |
Output is correct |
17 |
Correct |
24 ms |
384 KB |
Output is correct |
18 |
Correct |
126 ms |
1128 KB |
Output is correct |
19 |
Correct |
19 ms |
384 KB |
Output is correct |
20 |
Correct |
39 ms |
384 KB |
Output is correct |
21 |
Correct |
41 ms |
384 KB |
Output is correct |
22 |
Correct |
55 ms |
504 KB |
Output is correct |
23 |
Correct |
339 ms |
50180 KB |
Output is correct |
24 |
Correct |
851 ms |
144264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
635 ms |
37392 KB |
Output is correct |
2 |
Correct |
786 ms |
12888 KB |
Output is correct |
3 |
Correct |
788 ms |
6984 KB |
Output is correct |
4 |
Correct |
696 ms |
2124 KB |
Output is correct |
5 |
Correct |
542 ms |
920 KB |
Output is correct |
6 |
Correct |
584 ms |
1480 KB |
Output is correct |
7 |
Correct |
613 ms |
20128 KB |
Output is correct |
8 |
Correct |
556 ms |
10244 KB |
Output is correct |
9 |
Correct |
475 ms |
16048 KB |
Output is correct |
10 |
Correct |
434 ms |
8216 KB |
Output is correct |
11 |
Correct |
584 ms |
20216 KB |
Output is correct |
12 |
Correct |
565 ms |
10236 KB |
Output is correct |
13 |
Correct |
185 ms |
636 KB |
Output is correct |
14 |
Correct |
17 ms |
384 KB |
Output is correct |
15 |
Correct |
12 ms |
824 KB |
Output is correct |
16 |
Execution timed out |
7095 ms |
847596 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
1408 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
564 KB |
Output is correct |
18 |
Correct |
6 ms |
896 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
5 ms |
896 KB |
Output is correct |
21 |
Correct |
9 ms |
1152 KB |
Output is correct |
22 |
Correct |
3 ms |
768 KB |
Output is correct |
23 |
Correct |
6 ms |
896 KB |
Output is correct |
24 |
Correct |
5 ms |
768 KB |
Output is correct |
25 |
Correct |
8 ms |
1376 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
3 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
384 KB |
Output is correct |
36 |
Correct |
4 ms |
384 KB |
Output is correct |
37 |
Correct |
4 ms |
384 KB |
Output is correct |
38 |
Correct |
4 ms |
384 KB |
Output is correct |
39 |
Correct |
4 ms |
384 KB |
Output is correct |
40 |
Correct |
5 ms |
512 KB |
Output is correct |
41 |
Correct |
4 ms |
384 KB |
Output is correct |
42 |
Correct |
4 ms |
384 KB |
Output is correct |
43 |
Correct |
18 ms |
2428 KB |
Output is correct |
44 |
Correct |
23 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
665 ms |
9840 KB |
Output is correct |
2 |
Correct |
1526 ms |
41344 KB |
Output is correct |
3 |
Correct |
847 ms |
47892 KB |
Output is correct |
4 |
Correct |
551 ms |
1396 KB |
Output is correct |
5 |
Correct |
425 ms |
1572 KB |
Output is correct |
6 |
Correct |
419 ms |
948 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
45 ms |
384 KB |
Output is correct |
10 |
Correct |
13 ms |
384 KB |
Output is correct |
11 |
Correct |
364 ms |
1304 KB |
Output is correct |
12 |
Correct |
1506 ms |
1696 KB |
Output is correct |
13 |
Correct |
654 ms |
1264 KB |
Output is correct |
14 |
Correct |
425 ms |
1388 KB |
Output is correct |
15 |
Correct |
1373 ms |
1424 KB |
Output is correct |
16 |
Correct |
409 ms |
2524 KB |
Output is correct |
17 |
Correct |
1307 ms |
21428 KB |
Output is correct |
18 |
Correct |
6559 ms |
15912 KB |
Output is correct |
19 |
Correct |
2070 ms |
11320 KB |
Output is correct |
20 |
Correct |
221 ms |
976 KB |
Output is correct |
21 |
Correct |
2719 ms |
223360 KB |
Output is correct |
22 |
Correct |
585 ms |
38872 KB |
Output is correct |
23 |
Correct |
686 ms |
49524 KB |
Output is correct |
24 |
Correct |
607 ms |
55640 KB |
Output is correct |
25 |
Correct |
1764 ms |
239580 KB |
Output is correct |
26 |
Correct |
815 ms |
78632 KB |
Output is correct |
27 |
Correct |
3135 ms |
526060 KB |
Output is correct |
28 |
Correct |
332 ms |
504 KB |
Output is correct |
29 |
Correct |
645 ms |
55708 KB |
Output is correct |
30 |
Correct |
504 ms |
35660 KB |
Output is correct |
31 |
Correct |
127 ms |
796 KB |
Output is correct |
32 |
Correct |
160 ms |
976 KB |
Output is correct |
33 |
Correct |
134 ms |
792 KB |
Output is correct |
34 |
Correct |
258 ms |
1400 KB |
Output is correct |
35 |
Correct |
528 ms |
18756 KB |
Output is correct |
36 |
Correct |
532 ms |
18888 KB |
Output is correct |
37 |
Correct |
582 ms |
18744 KB |
Output is correct |
38 |
Correct |
536 ms |
18712 KB |
Output is correct |
39 |
Execution timed out |
7093 ms |
869276 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
680 ms |
9776 KB |
Output is correct |
2 |
Correct |
1529 ms |
41340 KB |
Output is correct |
3 |
Correct |
816 ms |
47908 KB |
Output is correct |
4 |
Correct |
519 ms |
1756 KB |
Output is correct |
5 |
Correct |
461 ms |
1020 KB |
Output is correct |
6 |
Correct |
462 ms |
888 KB |
Output is correct |
7 |
Correct |
427 ms |
1376 KB |
Output is correct |
8 |
Correct |
387 ms |
1004 KB |
Output is correct |
9 |
Correct |
630 ms |
11824 KB |
Output is correct |
10 |
Correct |
760 ms |
9456 KB |
Output is correct |
11 |
Correct |
658 ms |
11824 KB |
Output is correct |
12 |
Correct |
642 ms |
9176 KB |
Output is correct |
13 |
Correct |
687 ms |
11756 KB |
Output is correct |
14 |
Correct |
618 ms |
9516 KB |
Output is correct |
15 |
Correct |
247 ms |
632 KB |
Output is correct |
16 |
Correct |
219 ms |
600 KB |
Output is correct |
17 |
Correct |
179 ms |
504 KB |
Output is correct |
18 |
Correct |
66 ms |
488 KB |
Output is correct |
19 |
Correct |
507 ms |
888 KB |
Output is correct |
20 |
Correct |
505 ms |
888 KB |
Output is correct |
21 |
Correct |
440 ms |
764 KB |
Output is correct |
22 |
Correct |
672 ms |
156560 KB |
Output is correct |
23 |
Correct |
962 ms |
265776 KB |
Output is correct |
24 |
Correct |
659 ms |
5460 KB |
Output is correct |
25 |
Execution timed out |
7107 ms |
852824 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |