HDU3371--- Connect the Cities

一道很蛋疼的题,这道题过不过看运气,运气好700ms,运气不好就超时。(还有一次998ms我会乱说- -)

测试很多次int cmp()速度比bool cmp()速度快一点。

不用路径压缩比用了快一点。。。

#include
#include
#include
using namespace std;
#define ll long long
#define inf 0xfffff
#define MAX 25500
int p[510],n,m,s,kk,flag;
struct e
{
    int a,b,c;
};
e path[MAX];
bool cmp(const e &a, const e &b)
{
	return a.c1;i++)  //如果c==1则已经生成
        {
            int dx=find(path[i].a);
            int dy=find(path[i].b);
            if(dx!=dy)
            {
                sum+=path[i].c;
                p[dx]=dy;
                flag--;
            }

        }

    if(flag==1)
        printf("%d\n",sum);
    else
         printf("-1\n");
    }
}


 

你可能感兴趣的:(HDU3371--- Connect the Cities)