首页 > 其他 > 详细

Brexit Negotiations-反向拓扑

时间:2021-05-05 17:45:39      阅读:16      评论:0      收藏:0      [点我收藏+]

题目:

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;
}
View Code

 

完全妹想到反向拓扑 我甚至都没有反向的意思!!(菜 我的座右铭

有空再细想吧 赶计网报告

Brexit Negotiations-反向拓扑

原文:https://www.cnblogs.com/ReflexFox/p/14731839.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!