CROADS - Editorial

Can we use minimum spanning tree algorithm

Moreover it can be supported with the image below.

Nice approach. This can help to understand better

//same apporach but showing wrong
#include<bits/stdc++.h>
#define mod 1000000009
#define ll long long int
using namespace std;
int main()
{ ll t;
cin>>t;
while(t–)
{ll n,count=0,m;
cin>>n;
long double p;
p=log(n)/log(2);
if(p-(ll)p==0.0)
{printf("-1\n");
continue;}

count=(n-1)/2;
for(ll i=2;i<n;i=i2)
{
m=n/i;
count+=(m+1)/2
i;
}
cout<<count<<"\n";
}
}

Refer this Solution

What is meant by a city can be connected if it has a positive cost?

please explain the aproch of the formulae given in hint 3