I was trying to take input from a file and process it and then write the output to another file but I am getting runtime error. For small cases, the code works fine but for large cases, it gives runtime error.
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
int main()
{
ofstream output;
output.open("testOut.txt");
ifstream input;
input.open("input4.txt");
if(input.is_open())cout<<"input opened\n";
if(output.is_open())cout<<"output opened\n";
int v, e;
input >> v >> e;
int connection[v + 1] = {0};
int segTree[4 * v + 4];
vector<int> graph[v + 1];
int totalSum = 0;
for(int i=0;i<e;i++)
{
int e1,e2;
input>>e1>>e2;//Here I am getting the error
graph[e1].push_back(e2);
graph[e2].push_back(e1);
connection[e1]++;
connection[e2]++;
totalSum += 2;
}
int size = v;
buildTree(connection, segTree, 1, v, 1);
while (totalSum > 0)
{
int index = segTree[1];
for (int i = 0; i < graph[index].size(); i++)
{
if (connection[graph[index][i]] != -1)
{
update(connection, segTree, 1, v, graph[index][i], 1, connection[graph[index][i]] - 1);
totalSum -= 2;
}
}
update(connection, segTree, 1, v, index, 1, -1);
size--;
}
cout << size << "\n";
for (int i = 1; i < v + 1; i++)
{
if (connection[i] == -1)
cout << "0 ";
else
cout << "1 ";
}
output.close();
input.close();
return 0;
}
Here is the link to the input file (B4.txt).It is an a zip file containing 4 text files.