//拓朴排序
public class d4 {
public static List<node> tuopupaixu(graph g){
List<node> ans=new ArrayList<>();
HashMap<node,Integer> inmap=new HashMap<>();//入度表
Queue<node> zeroq=new LinkedList<>();//入度为0的点
for(node cur:g.nodes.values()){
inmap.put(cur,cur.in);
if(cur.in==0){
zeroq.add(cur);
}
}
while(!zeroq.isEmpty()){
node cur=zeroq.poll();
ans.add(cur);
for(node c:cur.nexts){
inmap.put(c,c.in-1);
if(c.in==0){
zeroq.add(c);
}
}
}
return ans;
}
}