每家廠商記錄自己供應的廠商

當某廠商出問題時

就從該廠商擴散出去

詳情請見程式

 

#include <iostream>
#include <vector>

using namespace std;

constexpr int MAX_STORE_NUM = 10001;

class Store
{
public:
    const bool isBad() const{ return m_bad; }
    void setBad(){ m_bad = true; }
    void addSubstore(const int &_to){ m_substore.push_back(_to); }
    void spread(Store []);

private:
    bool m_bad = false;
    vector<int> m_substore;
};

void Store::spread(Store _store[])
{
    m_bad = true;
    for(int i = 0; i<m_substore.size(); i+=1)
        if(!_store[m_substore[i]].isBad())
            _store[m_substore[i]].spread(_store);
}

int main()
{
    int store_num, apply_num, bad_store_num, query_num; 
    Store store[MAX_STORE_NUM];

    cin >> store_num >> apply_num >> bad_store_num >> query_num;

    while(apply_num--){
        int from, to;
        cin >> from >> to;
        store[from].addSubstore(to);
    }

    while(bad_store_num--){
        int store_id;
        cin >> store_id;

        store[store_id].setBad();
        store[store_id].spread(store);
    }

    while(query_num--){
        int query;
        cin >> query;
        if(store[query].isBad())
            cout << "TUIHUOOOOOO" << endl;
        else
            cout << "YA~~" << endl;
    }

    return 0;
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大神(偽) 的頭像
    大神(偽)

    大神的世界

    大神(偽) 發表在 痞客邦 留言(0) 人氣()