zoukankan      html  css  js  c++  java
  • P1113-杂务

    #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;
    }
  • 相关阅读:
    一些可以参考的常用工具库类整理
    Java(Android)线程池 总结
    JAVA泛型
    设计模式总结
    原型模式
    工厂模式与抽象工厂模式
    组合模式
    适配器模式
    建造者模式
    外观模式
  • 原文地址:https://www.cnblogs.com/Asurudo/p/11526774.html
Copyright © 2011-2022 走看看