i input test cases
5 5 ->5 is the aim node, 5 is edges
1 2 ->edges
2 3 ->Edges
3 4 ->Edges
2 5 ->Edges
4 5 ->Edges
i want to find shortest path to the aim node which is 5, but when i input this
test cases, it wont finish automatically , i need to input enter at last iteration why?
#include <iostream>
#include<vector>
#include<stdio.h>
usingnamespace std;
#define INF 100000;
int dist[1000000];
void addedge(vector<int>graph[],int u, int v){
graph[u].push_back(v);
graph[v].push_back(u);
}
int main()
{
vector<int>graph[100000];
int test = 0;
scanf("%d", &test);
while (test) {
bool visit[100000] = { false };
int tujuan = 0;
int vertices = 0;
int start,end;
int edges = 0;
scanf("%d %d", &aim, &edges);
vertices = edges + 1;
std::fill(dist, dist + vertices+1, 10000000);
for (int i = 1; i <edges+1; i++) { /* in fourth iteration, i need to enter in the end to finish last test case why?? */
start=0;
end=0;
scanf("%d %d", &start, &end);
addedge(graph,start,end);
}
dist[1] = 0;
for (int i = 1; i < vertices; i++) {
if (visit[i] == true)
continue;
else
visit[i] = true;
int y = graph[i].size();
for (int k = 0; k < graph[i].size(); k++) {
if (dist[graph[i][k]] > dist[i] + 1)
dist[graph[i][k]] = dist[i] + 1;
}
}
cout << dist[aim]<<"\n";
test--;
}
return 0;
}