s4553711
6/10/2017 - 3:13 PM

582.cpp

class Solution {
public:
    vector<int> killProcess(vector<int>& pid, vector<int>& ppid, int kill) {
        map<int, set<int> > children;
        vector<int> killed;
        for(int i = 0; i < ppid.size(); i++)
            children[ppid[i]].insert(pid[i]);
        killID(children, killed, kill);
        return killed;
    }
    void killID(map<int, set<int> >& v, vector<int>& killed, int kill) {
        killed.push_back(kill);
        for(int child: v[kill]) {
            killID(v, killed, child);
        }
    }
};