P1113 杂务

 1 #include<iostream>
 2 #include<fstream>
 3 #include<queue>
 4 #include<set>
 5 #include<cstdio>
 6 using namespace std;
 7 
 8 //#define cin fin
 9 
10 int maxt[10010];
11 set<int> before[10010];
12 int cnt[10010];
13 int len[10010];
14 //int testcnt;
15 int n;
16 queue<int>q;
17 
18 inline int max(int a, int b)
19 {
20     return a > b ? a : b;
21 }
22 
23 inline void topo()
24 {
25     for (register int i = 1; i <= n; i++)
26     {
27         if (!cnt[i])
28         {
29             q.push(i);
30             maxt[i] = len[i];
31         }
32     }
33     while (!q.empty())
34     {
35         int t = q.front();
36         q.pop();
37         for (register int i = t + 1; i <= n; i++)
38         {
39             //testcnt++;
40             if (cnt[i] && before[i].count(t))
41             {
42                 cnt[i]--;
43                 if (!cnt[i]) q.push(i);
44                 maxt[i] = max(maxt[i], maxt[t] + len[i]);
45                 before[i].erase(t);
46             }
47         }
48     }
49 }
50 
51 int main()
52 {
53     ios::sync_with_stdio(0);
54     //ifstream fin("d:\\testdata.in");
55     scanf("%d", &n);
56     for (register int i = 1; i <= n; i++)
57     {
58         register int a, b, c;
59         scanf("%d%d%d", &a, &b, &c);
60         len[a] = b;
61         while (c)
62         {
63             before[a].insert(c);
64             scanf("%d", &c);
65             cnt[a] ++;
66         }
67     }
68     topo();
69     int ans = 0;
70     for (register int i = 1; i <= n; i++)
71     {
72         ans = max(maxt[i], ans);
73     }
74     printf("%d", ans);
75     //cout << endl << testcnt;
76 }
View Code

 

posted on 2019-10-09 13:38  thjkhdf12  阅读(138)  评论(0)    收藏  举报