Super Mancunian

  • + 0 comments

    I am getting segmentation fault in all the test cases except one.Is it because my solution uses too much space or there is any other mistake in it.

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    long long int n,m,x,y,max1,min1,cost=0,cm=0,cn;
    cin>>n>>m;
    vector<long long int> a[n+1];
    long long int i,c[n+1][n+1];
    for(i=0;i<m;i++)
    {
        cin>>x>>y;
        if(x!=y)
        a[x].push_back(y);
        if(x!=y)
        a[y].push_back(x);
        cin>>c[x][y];
        c[y][x]=c[x][y];
        //sf[c[x][y]]++;
    }
    for(i=2;i<=n;i++)
    {
        for(unsigned long long int j=0;j<a[i].size();j++)
        {
            if(j==0)
            {
                min1=c[a[i][j]][i];
               /* if(i==0)
                    max1=min1;*/
            }
            /*if(max1==c[a[i][j]][i])
                cm++;*/
            else
            {
                if(min1>c[a[i][j]][i])
                    min1=c[a[i][j]][i];
            }
    
        }
        //cout<<min1;
        if(i==2)
            max1=min1;
        cost+=min1;
        if(max1<min1)
        {
            max1=min1;
        }
            //cout<<max1;
    }
    
        for(i=1;i<=n;i++)
        {
    
            for(unsigned long long int k=0;k<a[i].size();k++)
            {
                //cout<<c[a[i][k]][i]<<endl;
                if(c[a[i][k]][i]==max1)
                    cm++;
            }
        }
    cout<<cost-max1<<" "<<cm/2;
    return 0;
    }