P1113 杂务

Aimee

按照依赖顺序建图后,显然可以发现一个递推的关系,如果一个点入度为零,那么它就可以完成

这样从入度为零的点开始更新,删边,并且在度数又为零后加入待处理的队列

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int n;
struct b{
    int du;
    int tim;
}ta[10001];
int head[10001];
struct e{
    int to;
    int ne;
}ed[1000001];
int f[100001];
int x;
queue<int> q;
int vis[10001];
int p;
void add(int f,int to){
    p++;
    ed[p].to=to;
    ed[p].ne=head[f];
    head[f]=p;
}
void deal(){
    while(!q.empty()){
        int x=q.front();
        q.pop();
    //  cout<<x<<endl;
        if(vis[x]) continue;
        vis[x]=1;
        for(int i=head[x];i;i=ed[i].ne){
            f[ed[i].to]=max(f[ed[i].to],f[x]+ta[ed[i].to].tim);
            ta[ed[i].to].du--;
            if(ta[ed[i].to].du==0){
                q.push(ed[i].to);
            }
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",&x);
        scanf("%d",&ta[i].tim);
        scanf("%d",&x);
        while(x!=0){

            add(x,i);
            ta[i].du++;
            scanf("%d",&x); 
        }
    }
    for(int i=1;i<=n;++i){
        if(ta[i].du==0){
            q.push(i);
            f[i]=ta[i].tim;
        }
    } 
    deal();
    int znx=0;
    for(int i=1;i<=n;++i){
        znx=max(znx,f[i]);
    }
    cout<<znx;
    return 0;
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇