Skip to content

Commit

Permalink
Update 1857.Largest-Color-Value-in-a-Directed-Graph.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored May 11, 2021
1 parent 436a767 commit 86f8ec1
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class Solution {
int outD[100000];
vector<int>prev[100000];
int inD[100000];
vector<int>next[100000];
public:
int largestPathValue(string colors, vector<vector<int>>& edges)
{
int ans = 1;
for (auto edge: edges)
{
int a = edge[0], b = edge[1];
prev[b].push_back(a);
outD[a]++;
next[a].push_back(b);
inD[b]++;
}

unordered_set<char>Set(colors.begin(), colors.end());
Expand All @@ -27,15 +27,15 @@ class Solution {
{
int n = colors.size();
vector<int>count(n, 0);
vector<int>out(n, 0);
vector<int>in(n, 0);
for (int i=0; i<n; i++)
out[i] = outD[i];
in[i] = inD[i];

int nodes = 0;
queue<int>q;
for (int i=0; i<n; i++)
{
if (out[i]==0)
if (in[i]==0)
{
nodes++;
if (colors[i]-'a'==k) count[i]++;
Expand All @@ -49,12 +49,12 @@ class Solution {
auto cur = q.front();
q.pop();

for (auto p: prev[cur])
for (auto p: next[cur])
{
count[p] = max(count[p], count[cur]+ (colors[p]-'a'==k));
ret = max(ret, count[p]);
out[p]--;
if (out[p]==0)
in[p]--;
if (in[p]==0)
{
nodes++;
q.push(p);
Expand Down

0 comments on commit 86f8ec1

Please sign in to comment.