Re: [閒聊] 每日leetcode

作者: sixB (6B)   2025-01-24 22:08:02
802.
拓撲拉機獸
嗎?
class Solution {
public:
vector<int> eventualSafeNodes(vector<vector<int>>& graph) {
int n = graph.size();
vector<vector<int>> adj(n);
vector<int> out(n);
for(int i = 0; i < n; i++){
for(auto& node: graph[i]){
adj[node].push_back(i);
out[i]++;
}
}
vector<int> res;
queue<int> ter;
for(int i = 0; i < n; i++){
if(out[i] == 0){
ter.push(i);
res.push_back(i);
}
}
while(!ter.empty()){
int p = ter.front();
ter.pop();
for(auto& i: adj[p]){
if(

Links booklink

Contact Us: admin [ a t ] ucptt.com