stl - Does set<pair<long long,long long> > does not supports members first an second? -


 #include <bits/stdc++.h>  using namespace std;  #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ll long long int #define pb push_back #define mp make_pair #define pii pair<int,int> #define pll pair<ll,ll> #define pis pair< int,string>   #define test int t;cin>>t;while(t--) #define ff first // error: 'std::set<std::pair<long long int, long long int> >::iterator' has no member named 'first' #define ss second // error: 'std::set<std::pair<long long int, long long int> >::iterator' has no member named 'second' #define inf 1000000000 #define input(a,n) for(i=1;i<=n;i++)cin>>a[i]; #define output(a,n) for(i=1;i<=n;i++)cout<<a[i]<<" "; vector< vector<ll> > v(3002, vector<ll>(3002,-1)); set< pair<ll, ll> > se; set< pair<ll, ll> >::iterator it; int vis[3002]={0}; void exmin(ll a) {     ll x,des,val,min=inf;     for(x=0;x<v[a].size();x++)     {         if(v[a][x]<min)         {             val=v[a][x];             des=x;             min=val;         }     }     se.insert(mp(val,des)); }   int main() {    fast   ll n,m,x,i,j,k,wt=0,s;   cin>>n>>m;   vector<int> ve;   for(x=1;x<=n;x++)      ve.pb(x);   for(x=0;x<m;x++)   {     cin>>i>>j>>k;     if(v[i][j]!=-1)     {         if(v[i][j]>k)         {             v[i][j]=k;             v[j][i]=k;           }       }       else       {         v[i][j]=k;         v[j][i]=k;       }    }   cin>>s;   ve.erase(ve.begin()+s-1);   while(ve.size()!=0)   {     for(x=0;x<v[s].size();x++)     {         if(v[s][x]!=-1 && vis[x]!=1)         {             exmin(x);           }     } /*  for(x=0;x<p.size();x++)     {      }*/      it=se.begin();     wt=wt+*(it).ff;     s=*(it).ss;     vis[*(it).ss]=1;     ve.erase(ve.begin()+*(it).ss-1);      se.erase(it);   }  return 0; } 

still facing errors.
trying implement prim's algorithm.
not able include line numbers, hence attached errors along lines itself.
sorry , not including "abhorrent part" because error in part.

although have global set s

set< pair<ll, ll> > s; 

you have defined local variable s of type long long:

ll n,m,x,i,j,k,wt=0,s; 

which hides global s. long long has neither begin nor erase member functions since primitive type. hence errors:

 it=s.begin();    //error: request member 'begin' in 's', of non-class type 'long long int'   s.erase(it);  //error: request member 'erase' in 's', of non-class type 'long long int' 

to refer global s, use ::s, i.e.

::s.erase(it); 

and lastly want point out "contestese" coding style you're using abhorrent. feel free use during contests as like, please edit away when post questions on so.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -