#include <bits/stdc++.h>
using namespace std;
void just_do_it();
int main() {
#ifdef KAMIRULEZ
freopen("kamirulez.inp", "r", stdin);
freopen("kamirulez.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
just_do_it();
return 0;
}
struct edge {
int v, a, b;
edge(int _v, int _a, int _b): v(_v), a(_a), b(_b) {};
};
const int maxn = 2e5 + 20;
const int inf = 1e9 + 20;
vector<edge> adj[maxn];
int lt[maxn];
int rt[maxn];
bool flag[maxn];
bool dfs(int u, int x) {
if (x < lt[u]) {
return false;
}
if (x >= rt[u]) {
return true;
}
flag[u] = true;
for (auto e: adj[u]) {
if (x >= e.a) {
if (flag[e.v] || dfs(e.v, min(inf, x + e.b))) {
flag[u] = false;
rt[u] = x;
return true;
}
}
}
flag[u] = false;
lt[u] = x + 1;
return false;
}
void just_do_it() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v, a, b;
cin >> u >> v >> a >> b;
adj[u].emplace_back(v, a, b);
}
for (int i = 1; i <= n; i++) {
lt[i] = 0;
rt[i] = inf + 1;
}
for (int i = 1; i <= n; i++) {
int lt = 0;
int rt = inf;
int res = -1;
while (lt <= rt) {
int mt = (lt + rt) / 2;
if (dfs(i, mt)) {
res = mt;
rt = mt - 1;
}
else {
lt = mt + 1;
}
}
cout << res << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5076 KB |
Output is correct |
2 |
Correct |
4 ms |
5096 KB |
Output is correct |
3 |
Correct |
2 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
5 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5204 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
5 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5036 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
139 ms |
11880 KB |
Output is correct |
2 |
Correct |
140 ms |
11868 KB |
Output is correct |
3 |
Correct |
52 ms |
9024 KB |
Output is correct |
4 |
Correct |
48 ms |
7508 KB |
Output is correct |
5 |
Correct |
116 ms |
11080 KB |
Output is correct |
6 |
Correct |
114 ms |
11084 KB |
Output is correct |
7 |
Correct |
49 ms |
8396 KB |
Output is correct |
8 |
Correct |
889 ms |
27472 KB |
Output is correct |
9 |
Correct |
255 ms |
13608 KB |
Output is correct |
10 |
Correct |
45 ms |
7636 KB |
Output is correct |
11 |
Correct |
117 ms |
10448 KB |
Output is correct |
12 |
Correct |
37 ms |
8384 KB |
Output is correct |
13 |
Correct |
35 ms |
7488 KB |
Output is correct |
14 |
Correct |
785 ms |
27584 KB |
Output is correct |
15 |
Correct |
946 ms |
27472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5076 KB |
Output is correct |
2 |
Correct |
4 ms |
5096 KB |
Output is correct |
3 |
Correct |
2 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
5 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5204 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
5 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5036 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
139 ms |
11880 KB |
Output is correct |
16 |
Correct |
140 ms |
11868 KB |
Output is correct |
17 |
Correct |
52 ms |
9024 KB |
Output is correct |
18 |
Correct |
48 ms |
7508 KB |
Output is correct |
19 |
Correct |
116 ms |
11080 KB |
Output is correct |
20 |
Correct |
114 ms |
11084 KB |
Output is correct |
21 |
Correct |
49 ms |
8396 KB |
Output is correct |
22 |
Correct |
889 ms |
27472 KB |
Output is correct |
23 |
Correct |
255 ms |
13608 KB |
Output is correct |
24 |
Correct |
45 ms |
7636 KB |
Output is correct |
25 |
Correct |
117 ms |
10448 KB |
Output is correct |
26 |
Correct |
37 ms |
8384 KB |
Output is correct |
27 |
Correct |
35 ms |
7488 KB |
Output is correct |
28 |
Correct |
785 ms |
27584 KB |
Output is correct |
29 |
Correct |
946 ms |
27472 KB |
Output is correct |
30 |
Correct |
164 ms |
12196 KB |
Output is correct |
31 |
Correct |
144 ms |
12224 KB |
Output is correct |
32 |
Correct |
44 ms |
9396 KB |
Output is correct |
33 |
Correct |
44 ms |
7744 KB |
Output is correct |
34 |
Correct |
112 ms |
11512 KB |
Output is correct |
35 |
Correct |
143 ms |
11472 KB |
Output is correct |
36 |
Correct |
68 ms |
8744 KB |
Output is correct |
37 |
Correct |
941 ms |
27852 KB |
Output is correct |
38 |
Correct |
189 ms |
13584 KB |
Output is correct |
39 |
Correct |
48 ms |
8140 KB |
Output is correct |
40 |
Correct |
163 ms |
10892 KB |
Output is correct |
41 |
Correct |
45 ms |
8980 KB |
Output is correct |
42 |
Correct |
38 ms |
8056 KB |
Output is correct |
43 |
Correct |
833 ms |
27848 KB |
Output is correct |
44 |
Correct |
826 ms |
27864 KB |
Output is correct |
45 |
Correct |
1114 ms |
27852 KB |
Output is correct |
46 |
Correct |
693 ms |
17212 KB |
Output is correct |
47 |
Correct |
256 ms |
13392 KB |
Output is correct |
48 |
Correct |
121 ms |
11616 KB |
Output is correct |
49 |
Correct |
300 ms |
19452 KB |
Output is correct |
50 |
Correct |
3 ms |
4948 KB |
Output is correct |