-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj14567.cpp
More file actions
38 lines (31 loc) · 757 Bytes
/
boj14567.cpp
File metadata and controls
38 lines (31 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 1e3+5;
vector<int> prerequisite[MAX];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int N, M;
cin>>N>>M;
int dp[N + 1];
fill(dp, dp+N+1, 1);
for (int i = 0, a, b; i < M; ++i) {
cin>>a>>b;
prerequisite[b].push_back(a);
}
for (int i = 1; i <= N; ++i) {
if(!prerequisite[i].empty()){
int maxValue = INT32_MIN;
for(int prev: prerequisite[i]){
maxValue = max(maxValue, dp[prev]);
}
dp[i] += maxValue;
}
}
for (int i = 1; i <= N; ++i) {
cout<<dp[i]<<' ';
}
cout<<'\n';
return 0;
}