#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 - 1, x + e.b))) {
flag[u] = false;
rt[u] = min(x, inf - 1);
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;
}
for (int i = 1; i <= n; i++) {
int lt = 1;
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 |
5 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
2 ms |
5076 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
54 ms |
5240 KB |
Output is correct |
9 |
Incorrect |
4 ms |
5076 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
237 ms |
11892 KB |
Output is correct |
2 |
Correct |
174 ms |
11772 KB |
Output is correct |
3 |
Correct |
79 ms |
9020 KB |
Output is correct |
4 |
Correct |
53 ms |
7604 KB |
Output is correct |
5 |
Correct |
167 ms |
11104 KB |
Output is correct |
6 |
Correct |
159 ms |
11132 KB |
Output is correct |
7 |
Correct |
64 ms |
8348 KB |
Output is correct |
8 |
Execution timed out |
2075 ms |
25496 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
2 ms |
5076 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
54 ms |
5240 KB |
Output is correct |
9 |
Incorrect |
4 ms |
5076 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |