#define MAXN 10001 vector<int> followUpTask[MAXN];//邻接表存图,对于下标为i的节点,其存储的为i的后续任务 int inDrgee[MAXN]; //入度 int timeNeed[MAXN]; //任务所需时间 int timeOver[MAXN]; //第i号任务总耗时
int n; //图的节点数
int _max(int a, int b) { return a > b ? a : b; }
inttuopu(){ queue<int> q; for (int i = 1; i <= n; i++) { if (!inDrgee[i]) { //统计入度为0的点,放入队列,准备拓扑排序 q.push(i); timeOver[i] = timeNeed[i]; //对于入度为0的点,它的总耗时就是自己任务所需时间 } }
while (q.size()) { //pre 存取的是入度为0的点(任务可以独立进行,或任务前置任务已经完成的任务点) int pre = q.front(); q.pop();
int itime[10001]; int finishTime[10001]; vector<int> prepare[10001];
int _max(int a, int b) { return a > b ? a : b; }
intmain(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n;
int idx; for (int i = 1; i <= n; i++) { cin >> idx >> itime[i];
int prepa; cin >> prepa; while (prepa) { prepare[i].push_back(prepa); cin >> prepa; } }
int ans = 0; finishTime[1] = itime[1]; for (int i = 2; i <= n; i++) { for (auto& t : prepare[i]) { finishTime[i] = _max(finishTime[i], finishTime[t] + itime[i]); } ans = _max(ans, finishTime[i]); }