Please help me to find the error

code is as:
#include<bits/stdc++.h>
using namespace std;
int find(long long * d,bool * v,int n)
{
int mv=INT_MAX,mi=-1;
for(int i=1;i<=n;i++)
{
if(d[i]<mv&&!v[i])
{
mv=d[i];
mi=i;
}
}
return mi;
}
void res(vector<vector < long long > > graph,int n,int s)
{
long long dist[n+1];
bool vis[n+1];
for(int i=0;i<=n;i++)
{
dist[i]=INT_MAX;
vis[i]=0;
}
dist[s]=0;
int k=s;
while(k!=-1)
{
// cout<<k<<endl;
vis[k]=1;
for(int i=1;i<=n;i++)
{
if(graph[k][i]!=INT_MAX&&!vis[i]&&dist[k]!=INT_MAX)
{
dist[i]=min(dist[i],dist[k]+graph[k][i]);
}
}
k=find(dist,vis,n);
}
for(int i=1;i<=n;i++)
{if(i!=s)
{
if(dist[i]==INT_MAX)
cout<<"-1 “;
else
cout<<dist[i]<<” ";
}
}
cout<<endl;

}
int main() {
int t,n,m;
cin>>t;
while(t–)
{
cin>>n>>m;
vector< vector< long long > > graph;
// cout<<graph.size();
vector k;
for(int i=0;i<=n;i++)
{
k.push_back(INT_MAX);
}
// cout<<" “<<k.size();
for(int i=0;i<=n;i++)
{
graph.push_back(k);
// cout<<graph.size()<<” “<<graph[0].size()<<endl;
}
//cout<<graph.size()<<” "<<graph[0].size()<<endl;
for(int i=0;i<m;i++)
{
int x,y,r;
cin>>x>>y>>r;
graph[x][y]=r;
graph[y][x]=r;
}
int s;
cin>>s;
res(graph,n,s);
}
return 0;
}

Hi @dakshi, please provide your code using coding blocks ide : -https://ide.codingblocks.com/
due to formatting some lines are not shown up.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

@dakshi
Try to debug once with this test case
Q : 20 54
1 7 45
2 14 15
3 7 29
4 1 48
5 1 66
6 7 17
7 14 15
8 14 43
9 1 27
10 1 33
11 14 64
12 14 27
13 7 66
14 7 54
15 14 56
16 7 21
17 1 20
18 1 34
19 7 52
20 14 14
9 14 9
15 1 39
12 1 24
9 1 16
1 2 33
18 1 46
9 1 28
15 14 3
12 1 27
1 2 5
15 1 34
1 2 28
9 7 16
3 7 23
9 7 21
9 14 19
3 1 20
3 1 5
12 14 19
3 14 2
12 1 46
3 14 5
9 14 44
6 14 26
9 14 16
9 14 34
6 7 42
3 14 27
1 7 9
1 7 41
15 14 19
12 7 13
3 7 10
1 7 2
17

A : 20 25 25 68 86 39 22 70 36 53 91 35 88 27 30 43 54 74 41

answer does not match and unable to find error

@dakshi
Line 69 and 70
Since there are multiple edges possible between same set of nodes you need to keep min of those weights between them
graph[x][y] = min(graph[x][y],r);
graph[y][x] = min(graph[y][x],r);

Kindly close this doubt