PTA week10

//
//  main.c
//  Bonus2
//
//  Created by 余南龙 on 2016/11/27.
//  Copyright © 2016年 余南龙. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 200000
#define Infinity 10000000

struct Edge{
    int u;
    int v;
    int weight;
    int status;
};

int comp(const void *a, const void *b){
    struct Edge *pa = (struct Edge*)a;
    struct Edge *pb = (struct Edge*)b;

    if(pa->status != pb->status){
        return pb->status - pa->status;
    }
    return pa->weight - pb->weight;
}

int main() {
    struct Edge E[MAX];
    , connect, index, fu, fv, tmp, flag = , cost[MAX], UF[MAX];

    scanf("%d%d", &N, &M);
    ; i < M; i++){
        scanf("%d%d%d%d", &E[i].u, &E[i].v, &E[i].weight, &E[i].status);
    }
    qsort(E, M, ]), comp);
    memset(cost, , ));

    ; i <= N; i++){
        connect = ;
        memset(UF, -, ));
        ; j < M; j++){
            if(E[j].u != i&&E[j].v != i){
                index = fu = E[j].u;
                ){
                    fu = UF[fu];
                }
                while(index != fu){
                    tmp = UF[index];
                    UF[index] = fu;
                    index = tmp;
                }

                index = fv = E[j].v;
                ){
                    fv = UF[fv];
                }
                while(index != fv){
                    tmp = UF[index];
                    UF[index] = fv;
                    index = tmp;
                }

                if(fu != fv){
                    if(fu <= fv){
                        UF[fu] += UF[fv];
                        UF[fv] = fu;
                    }
                    else{
                        UF[fv] += UF[fu];
                        UF[fu] = fv;
                    }

                    connect++;
                     == E[j].status){
                        cost[i] += E[j].weight;
                    }
                    )
                        break;
                }
            }
        }
        ){
            cost[i] = Infinity;
        }
        if(cost[i] > max){
            max = cost[i];
        }
    }

     != max){
        ; i <= N; i++){
            if(max == cost[i]){
                 == flag){
                    printf("%d", i);
                    flag = ;
                }
                else{
                    printf(" %d", i);
                }
            }
        }
    }
    else{
        printf(");
    }
}
上一篇:ajax调用WebService实现数据库操作


下一篇:noip2016 Day1T3