Advertisement
aqibm

Untitled

Mar 9th, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. int findLongestPath(vector<int> topSortOrder, vector<vector<int>>& g) {
  2. int n = topSortOrder.size();
  3. vector<int> dist(n,0);
  4. int ans = 0;
  5. for(int i=0;i<n;i++) {
  6. int node = topSortOrder[i];
  7. for(auto& ch: g[node]) {
  8. dist[ch] = max(dist[ch], 1 + dist[node]);
  9. ans = max(ans,dist[ch]);
  10. }
  11. }
  12. return ans;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement