How to make the max number of vertices is 6000 The following

How to make the max number of vertices is 6000?

The following code works 100% using Xcode, but when i run the code using the Autograder, i got the following error `Time out error, probably infinite loop C++` as showing in the image below.

Does this means that my arrays are too small?

Input:

4 6

Women Conservatives Neocons Veterans

Trump Women 1

Trump Conservatives 1

Trump Neocons 5

Women Neocons 1

Neocons Veterans 5

Conservatives Veterans 1

**Output:**

8

**Here\'s My code:**

#include
#include
#include
#include
#include
#include
#include
  
using namespace std;
/*map Group Name to a Integer
useful for representation of graph
*/
map nameToNumber;
/*
adjacency matrix to represent graph
this will work since number of nodes is less
*/
int graph[301][301];
/*
recursion to find if target is reachable from src in graph
par == parent of src.. useful to keep track of visited nodes
*/
  
bool reachable(int src, int target, int par = -1)
{
if (src == target) return true;
  
bool isReachable = false;
  
for (int i = 0; i < 100; ++i)
{
if (i != par && graph[src][i] != 0 && reachable(i, target, src))
{
isReachable = true;
}
}
return isReachable;
}
  
int main()
{
int n, m;
cin >> n >> m;
// add names to map
for (int i = 0; i < n; ++i) {
string name;
cin >> name;
nameToNumber[name] = i;
}
  
vector >> edges;
// input edges
for (int i = 0; i < m; ++i)
{
string u, v; int w;
cin >> u >> v >> w;
edges.push_back(make_pair(w, make_pair(nameToNumber[v], nameToNumber[u])));
}
// sort edges based in increasing weights
sort(edges.begin(), edges.end());
  
int cost = 0;
for (int i = 0; i < edges.size(); ++i) {
int u = edges[i].second.first;
int v = edges[i].second.second;
int w = edges[i].first;
// check if u-v edge causes cycle
  
if (!reachable(u, v)) {
graph[u][v] = 1;
cost += w;
}
}
  
cout << cost ;
  
return 0;
}

**Everytime i run my code using the Autograder i get the following error `Time out error, probably infinite loop`.**

141.215.80.43 Files Warnings on... Create a site Student Out... Student Out... WordPress T... On Results: Passes test case 1 Fails test case 2. No hint Fails test case 3.No hint Fails test case 4. No hint Fails test case 5. No hint Fails test case 6. No hint Fails test case 7. No hint Fails test case 8. No hint Fails test case 9 Time out error, probably infinite loop. Fails test case 10 Time out error, probably infinite loop. Fails test case 11. No hint Fails test case 12. No hint You scored 1 out of 12 You have used 3 of your 8 total attempts. IMI COLLEGE OFENGINEERING & COMPUTER SCIENCE DEARBORN UNIVERSITY OF MICHIGAN-DEARBORN

Solution

`Time out error, probably infinite loop C++` : This error mainly occurs if you try to modify any iterator variable in any loop.

But in your case if for 6000 vertices Autograder might not work the way you are expecting . so try using vector instead of fixed size arrays

How to make the max number of vertices is 6000? The following code works 100% using Xcode, but when i run the code using the Autograder, i got the following err
How to make the max number of vertices is 6000? The following code works 100% using Xcode, but when i run the code using the Autograder, i got the following err
How to make the max number of vertices is 6000? The following code works 100% using Xcode, but when i run the code using the Autograder, i got the following err

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site