Skip to content

Commit 8819d24

Browse files
committed
Runtime: 1127 ms (Top 43.58%) | Memory: 202.6 MB (Top 28.30%)
1 parent 1dff090 commit 8819d24

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1+
// Runtime: 1127 ms (Top 43.58%) | Memory: 202.6 MB (Top 28.30%)
12
class Solution {
23
public:
34
int largestPathValue(string colors, vector<vector<int>>& edges) {
45
int n = colors.length();
56
unordered_map<int,vector<int>> graph;
67
vector<int> indegree(n,0);
7-
8+
89
for(auto e:edges){
910
graph[e[0]].push_back(e[1]);
1011
indegree[e[1]]++;
1112
}
12-
13+
1314
vector<vector<int>> charcount(n,vector<int>(26,0));
14-
15+
1516
queue<int> q;
16-
17+
1718
for(int i=0;i<n;i++){
1819
if(indegree[i]==0){
1920
q.push(i);
2021
}
2122
}
22-
23+
2324
int visited=0,ans=0;
24-
25+
2526
while(!q.empty()){
2627
int curr = q.front();
2728
q.pop();
2829
visited++;
29-
30+
3031
ans = max(ans,++charcount[curr][colors[curr]-'a']);
31-
32+
3233
for(auto v:graph[curr]){
3334
indegree[v]--;
3435
if(indegree[v]==0)
@@ -38,10 +39,10 @@ class Solution {
3839
}
3940
}
4041
}
41-
42+
4243
if(visited!=n)
4344
return -1;
44-
45+
4546
return ans;
4647
}
47-
};
48+
};

0 commit comments

Comments
 (0)