You are viewing a single comment's thread. Return to all comments →
Wrote this code and got a tle on test case 6 only. Help any one ??
void solve(){ ll n,e; cin>>n>>e; unordered_map<ll,list<ll>> m; vector<ll> dis(n+1,INT_MAX); queue<ll> q; set<ll> l; for(ll i=0;i<n;i++){ l.insert(i+1); } for(ll i=0;i<e;i++){ ll a,b; cin>>a>>b; m[a].push_back(b); m[b].push_back(a); } ll start; cin>>start; q.push(start); l.erase(start); dis[start]=0; while(!q.empty() and l.size()){ ll p=q.front(); q.pop(); list<ll> ne; for(ll x:l){ if(find(m[p].begin(),m[p].end(),x)==m[p].end()){ ne.push_back(x); } } for(ll x:ne){ q.push(x); dis[x]=dis[p]+1; l.erase(x); } } for(auto a:dis){ if(a==0 or a==INT_MAX) continue; cout<<a<<" "; } cout<<endl; }
Seems like cookies are disabled on this browser, please enable them to open this website
Rust & Murderer
You are viewing a single comment's thread. Return to all comments →
Wrote this code and got a tle on test case 6 only. Help any one ??