Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

做过3723帮忙看看为什么总是WA呢?

Posted by nosight at 2009-05-04 23:11:03
// 用的Kruskal构造最小生成树,应该是很简单的,但就是WA
#include <stdio.h>
typedef struct {
    int x;
    int y;
    int d;
} Rel;

int cmp(const void* r1, const void* r2) { return ((*(Rel *)r2).d)-((*(Rel *)r1).d); }

int main()
{
    int t, i, n, m, r;
    int cost;
    int used_x[10000], used_y[10000];
    Rel rels[50000];
    scanf("%d", &t);
    while(t--)
    {
	memset(used_x, 0, sizeof(used_x));
	memset(used_y, 0, sizeof(used_y));
	scanf("%d %d %d", &n, &m, &r);
	for(i = 0; i != r; ++i)
	    scanf("%d %d %d", &(rels[i].x), &(rels[i].y), &(rels[i].d));
	cost = (n+m)*10000;
	qsort(rels, r, sizeof(rels[0]), cmp);
	for(i = 0; i != r; ++i)
	{
	    if((used_x[rels[i].x]+used_y[rels[i].y]) < 2)
	    {
		used_x[rels[i].x] = 1;
		used_y[rels[i].y] = 1;
		cost -= rels[i].d;
	    }
	}
	printf("%d\n", cost);
    } 
    return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator