why do i always get garbage values? I have a problem about garbage values. I wrote this code but i have no idea why it always returns garbage values. Is that because of passing and returning array values? Or is there some other issues? this is c++ code . . . . . . . . . . .
#include<iostream>
#include<queue>
#include<vector>
#define MAX 1000
using namespace std;
int* topologicalSort(int*time, int*indegree, vector<int>*g, int n)
{
queue<int>q;
int result[MAX + 1];
memset(result, sizeof(result), 0);
for (int i = 1; i <= n; i++)
{
if (indegree[i] == 0) {
q.push(i);
result[i] = time[i];
}
}
while (!q.empty())
{
int x = q.front();
q.pop();
for (int i = 0; i < g[x].size(); i++)
{
int y = g[x][i];
indegree[y]--;
result[y] = max(result[y], result[x] + time[y]);
if (indegree[y] == 0)
q.push(y);
}
}
return result;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t-- > 0)
{
vector<int>g[MAX + 1];
int n;
int time[MAX + 1];
int indegree[MAX + 1];
int k;
int dest;
memset(time, sizeof(time), 0);
memset(indegree, sizeof(indegree), 0);
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
cin >> time[i];
}
for (int i = 0; i < k; i++)
{
int u, v;
cin >> u >> v;
g[u].push_back(v);
indegree[v]++;
}
cin >> dest;
int *r = topologicalSort(time, indegree, g, n);
cout << r[dest] << '\n';
}
}
.... .... .... .... .... ....