#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
struct EDGE {
int x, y, z, t;
} e[200005];
bool cmp(EDGE aa, EDGE bb) {
return aa.z < bb.z;
}
vector<int> gg[200005];
int d[200005], da[200005], f[200005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y, z, t;
cin >> x >> y >> z >> t;
d[x]++;
e[i] = {x, y, z, t};
}
sort(e + 1, e + m + 1, cmp);
queue<int> q;
for (int i = 1; i <= m; i++) {
gg[e[i].y].push_back(i);
}
for (int i = 1; i <= n; i++) {
if (d[i] == 0) q.push(i);
f[i] = 2e9;
}
while (!q.empty()) {
int p = q.front();
q.pop();
f[p] = -1;
for (int w : gg[p]) {
d[e[w].x]--;
da[w] = 1;
if (d[e[w].x] == 0) {
q.push(e[w].x);
}
}
}
for (int i = m; i >= 1; i--) {
if (da[i]) continue;
f[e[i].x] = min(f[e[i].x], e[i].z);
d[e[i].x]--;
da[i] = 1;
if (d[e[i].x] == 0) {
queue<int> q;
q.push(e[i].x);
while (!q.empty()) {
int p = q.front();
q.pop();
for (int w : gg[p]) {
if (da[w] == 1) continue;
f[e[w].x] = min(f[e[w].x], max(f[p] - e[w].t, e[w].z));
da[w] = 1;
d[e[w].x]--;
if (d[e[w].x] == 0) {
q.push(e[w].x);
}
}
}
}
}
for (int i = 1; i <= n; i++) cout << f[i] << " ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8528 KB |
Output is correct |
2 |
Correct |
2 ms |
8528 KB |
Output is correct |
3 |
Correct |
2 ms |
8528 KB |
Output is correct |
4 |
Correct |
2 ms |
8528 KB |
Output is correct |
5 |
Correct |
2 ms |
8528 KB |
Output is correct |
6 |
Correct |
2 ms |
8528 KB |
Output is correct |
7 |
Correct |
2 ms |
8528 KB |
Output is correct |
8 |
Correct |
2 ms |
8528 KB |
Output is correct |
9 |
Correct |
2 ms |
8528 KB |
Output is correct |
10 |
Correct |
2 ms |
8528 KB |
Output is correct |
11 |
Correct |
2 ms |
8528 KB |
Output is correct |
12 |
Correct |
2 ms |
8528 KB |
Output is correct |
13 |
Correct |
2 ms |
8628 KB |
Output is correct |
14 |
Correct |
2 ms |
8528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
15432 KB |
Output is correct |
2 |
Correct |
90 ms |
15324 KB |
Output is correct |
3 |
Correct |
57 ms |
11848 KB |
Output is correct |
4 |
Correct |
15 ms |
10320 KB |
Output is correct |
5 |
Correct |
90 ms |
14920 KB |
Output is correct |
6 |
Correct |
89 ms |
14664 KB |
Output is correct |
7 |
Correct |
61 ms |
11592 KB |
Output is correct |
8 |
Correct |
107 ms |
18748 KB |
Output is correct |
9 |
Correct |
104 ms |
17480 KB |
Output is correct |
10 |
Correct |
59 ms |
11592 KB |
Output is correct |
11 |
Correct |
79 ms |
13896 KB |
Output is correct |
12 |
Correct |
43 ms |
11508 KB |
Output is correct |
13 |
Correct |
42 ms |
11208 KB |
Output is correct |
14 |
Correct |
107 ms |
18760 KB |
Output is correct |
15 |
Correct |
104 ms |
18688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8528 KB |
Output is correct |
2 |
Correct |
2 ms |
8528 KB |
Output is correct |
3 |
Correct |
2 ms |
8528 KB |
Output is correct |
4 |
Correct |
2 ms |
8528 KB |
Output is correct |
5 |
Correct |
2 ms |
8528 KB |
Output is correct |
6 |
Correct |
2 ms |
8528 KB |
Output is correct |
7 |
Correct |
2 ms |
8528 KB |
Output is correct |
8 |
Correct |
2 ms |
8528 KB |
Output is correct |
9 |
Correct |
2 ms |
8528 KB |
Output is correct |
10 |
Correct |
2 ms |
8528 KB |
Output is correct |
11 |
Correct |
2 ms |
8528 KB |
Output is correct |
12 |
Correct |
2 ms |
8528 KB |
Output is correct |
13 |
Correct |
2 ms |
8628 KB |
Output is correct |
14 |
Correct |
2 ms |
8528 KB |
Output is correct |
15 |
Correct |
93 ms |
15432 KB |
Output is correct |
16 |
Correct |
90 ms |
15324 KB |
Output is correct |
17 |
Correct |
57 ms |
11848 KB |
Output is correct |
18 |
Correct |
15 ms |
10320 KB |
Output is correct |
19 |
Correct |
90 ms |
14920 KB |
Output is correct |
20 |
Correct |
89 ms |
14664 KB |
Output is correct |
21 |
Correct |
61 ms |
11592 KB |
Output is correct |
22 |
Correct |
107 ms |
18748 KB |
Output is correct |
23 |
Correct |
104 ms |
17480 KB |
Output is correct |
24 |
Correct |
59 ms |
11592 KB |
Output is correct |
25 |
Correct |
79 ms |
13896 KB |
Output is correct |
26 |
Correct |
43 ms |
11508 KB |
Output is correct |
27 |
Correct |
42 ms |
11208 KB |
Output is correct |
28 |
Correct |
107 ms |
18760 KB |
Output is correct |
29 |
Correct |
104 ms |
18688 KB |
Output is correct |
30 |
Correct |
92 ms |
15432 KB |
Output is correct |
31 |
Correct |
101 ms |
15368 KB |
Output is correct |
32 |
Correct |
57 ms |
11592 KB |
Output is correct |
33 |
Correct |
16 ms |
10320 KB |
Output is correct |
34 |
Correct |
86 ms |
14812 KB |
Output is correct |
35 |
Correct |
80 ms |
14808 KB |
Output is correct |
36 |
Correct |
63 ms |
11592 KB |
Output is correct |
37 |
Correct |
105 ms |
18760 KB |
Output is correct |
38 |
Correct |
111 ms |
16860 KB |
Output is correct |
39 |
Correct |
56 ms |
11624 KB |
Output is correct |
40 |
Correct |
97 ms |
13896 KB |
Output is correct |
41 |
Correct |
42 ms |
11592 KB |
Output is correct |
42 |
Correct |
41 ms |
11120 KB |
Output is correct |
43 |
Correct |
108 ms |
18760 KB |
Output is correct |
44 |
Correct |
98 ms |
18724 KB |
Output is correct |
45 |
Correct |
105 ms |
18760 KB |
Output is correct |
46 |
Correct |
73 ms |
15176 KB |
Output is correct |
47 |
Correct |
66 ms |
14736 KB |
Output is correct |
48 |
Correct |
78 ms |
14664 KB |
Output is correct |
49 |
Correct |
77 ms |
14676 KB |
Output is correct |
50 |
Correct |
2 ms |
8528 KB |
Output is correct |