11228 - Transportation system.

All about problems in Volume 112. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

maruf11
New poster
Posts: 1
Joined: Sat Jul 30, 2016 8:40 am

Re: 11228 - Transportation system.

Post by maruf11 » Sat Jul 30, 2016 9:39 am

someone plz help me out of here.
why i am getting compil error??
my code is here
#include<bits/stdc++.h>
#include<cmath>
using namespace std;


struct node{
int x,y;

}a[1010];

struct edge
{
int u,v;
double w;
bool operator <(const edge &p) const
{
return w<p.w;
}
};
int pr[1010];
vector<struct edge>e;
edge get;

int find_root(int x)
{
if(x==pr[x])
return x;
else
return pr[x]=find_root(pr[x]);
}
int mst(int n,int r)
{
int i,j;
double s1=0;
double s2=0;
int r1=0;
int r2=0;
int u=0,v=0;
edge temp;
for(i=0;i<e.size();i++)
{
temp=e;
u=find_root(temp.u);
v=find_root(temp.v);
if(u!=v)
{
if(temp.w<=r)
s1+=temp.w;
else
{
s2+=temp.w;
r2 ++;
}

pr=v;
}
}
int a=round(s1);
int b=round(s2);
cout<<(r2+1)<<" "<<a<<" "<<b<<endl;
}

int clr()
{
e.clear();
for(int i=0;i<1010;i++)
{
pr=0;
a.x=0;
a.y=0;
}
}

int main()
{
int i,j,k,l,n,m;
int t,r;
cin>>t;
int cas=1;
while(t--)
{
cin>>n>>r;
for(i=0;i<n;i++)
{
cin>>a.x>>a.y;
pr=i;
}

for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
get.u=i;
get.v=j;
get.w=sqrt(pow((a.x-a[j].x),2)+pow((a.y-a[j].y),2));
e.push_back(get);
}
}
sort(e.begin(),e.end());
printf("Case #%d: ",cas);
mst(n,r);
cas++;
clr();
}
return 0;
}

Post Reply

Return to “Volume 112 (11200-11299)”