题目:
https://vjudge.net/contest/437107#problem/B
https://codeforces.com/gym/102483/problem/B
思路:
反向拓扑找最小时间
#include<bits/stdc++.h> using namespace std; const int mx=4e5+10; typedef long long ll; ll n, rd[mx]; ll ans; vector<ll>e[mx]; struct node{ ll id, time; bool operator <(const node tmp)const{ return time>tmp.time; } }nos[mx]; priority_queue<node>q; bool ok[mx]; void solve(){ scanf("%lld", &n); for(ll i=1;i<=n;i++){ ll ee, d, b; scanf("%lld %lld", &ee, &d); nos[i].id=i, nos[i].time=ee; for(ll j=1;j<=d;j++){ scanf("%lld", &b);//d->i // rd[i]++; rd[b]++; e[i].push_back(b); // e[b].push_back(i); } } for(ll i=1;i<=n;i++){ if(rd[i]==0){ q.push(nos[i]); ok[nos[i].id]=true; } } node tmp; ll num=n-1; while(!q.empty()){ tmp=q.top();q.pop(); ok[tmp.id]=true; // printf("%lld:%lld\n", num, tmp.id); ans=max(ans, num+nos[tmp.id].time); num--; for(ll i=0;i<e[tmp.id].size();i++){ ll to=e[tmp.id][i]; rd[to]--; if(rd[to]==0 && ok[to]==false )q.push(nos[to]); } } printf("%lld\n", ans); } int main() { solve(); return 0; }
完全妹想到反向拓扑 我甚至都没有反向的意思!!(菜 我的座右铭
有空再细想吧 赶计网报告
原文:https://www.cnblogs.com/ReflexFox/p/14731839.html