Skip to content

Commit 848e22c

Browse files
authored
Add files via upload
1 parent 332b493 commit 848e22c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//luogu P1113
2+
//dfs式拓扑排序
3+
4+
#include<bits/stdc++.h>
5+
using namespace std;
6+
typedef long long ll;
7+
const int N = 1e4+5;
8+
int t[N],f[N]; //时间和答案
9+
vector<int>edge[N];
10+
11+
int dfs(int x) {
12+
if(f[x])return f[x]; //已经被访问过
13+
for(int i=0; i<edge[x].size(); i++) { //循环:x的每条出边指向的点
14+
f[x] = max(f[x],dfs(edge[x][i])); //dp,求pre最大值
15+
};
16+
f[x]+=t[x];
17+
return f[x];
18+
}
19+
20+
int main() {
21+
int n;
22+
cin>>n;
23+
for(int i=1; i<=n; i++) {
24+
int x,y;
25+
cin>>x>>t[i];
26+
cin>>y;
27+
while(y) {
28+
edge[y].push_back(x); //y->x
29+
cin>>y;
30+
}
31+
};
32+
int ans = 0;
33+
for(int i=1; i<=n; i++)ans = max(ans,dfs(i));
34+
cout<<ans;
35+
return 0;
36+
}

0 commit comments

Comments
 (0)