加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

P1113-杂务

发布时间:2020-12-15 07:44:50 所属栏目:Java 来源:网络整理
导读:#include bits/stdc++.h using namespace std; #define pb push_back #define _for(i,a,b) for(int i = (a);i (b);i ++) #define INF 100000003 #define ll long long inline ll read(){ ll ans = 0 ; char ch = getchar(),last = ‘ ‘ ; while (!isdigit(c
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define _for(i,a,b) for(int i = (a);i < (b);i ++)
#define INF 100000003
#define ll long long
inline ll read()
{
    ll ans = 0;
    char ch = getchar(),last =  ;
    while(!isdigit(ch)) last = ch,ch = getchar();
    while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - 0,ch = getchar();
    if(last == -) ans = -ans;
    return ans;
}
inline void write(ll x)
{
    if(x < 0) x = -x,putchar(-);
    if(x >= 10) write(x / 10);
    putchar(x % 10 + 0);
}

vector<int> G[10003];
int T[10003];
int con[10003];
int n; 
int main()
{
    n = read();
    _for(i,1,n+1)
    {
        read();
        T[i] = read();
        int t;
        while(t = read())
        {
            if(!t)
                break;
            else
                G[t].pb(i);
            con[i] ++;
        }
    }

    int t = 0;
    queue<int> q;
    q.push(1);
    q.push(0);
    while(q.size()!=1)
    {
        while(q.front())
        {
            int x = q.front();
            q.pop();
            T[x]--;
            if(T[x])
                q.push(x);
            else
                _for(i,0,G[x].size())
                {
                    con[G[x][i]] --;
                    if(!con[G[x][i]])
                        q.push(G[x][i]);
                }
        }
        q.pop();
        q.push(0);
        t ++;
    }
    write(t);
    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读