#include
#include
#include
#include
using namespace std;
const int inf = (1<<31)-10;
const int maxv = 510, maxe = 2e5;
int N, M;
int cost[maxv], fa[maxv];
struct Edge{
int x, y, c, s;
void read(){
scanf("%d%d%d%d", &x, &y, &c, &s);
}
bool operator<(const Edge e)const{
return s == e.s ? c < e.c : s > e.s;
}
}edge[maxe];
int get(int x){
return x == fa[x] ? x : fa[x] = get(fa[x]);
}
int main(){
scanf("%d%d", &N, &M);
for(int i = 0; i < M; i++) edge[i].read();
sort(edge, edge + M);
int ans = 0;
for(int i = 1; i <= N; i++){
cost[i] = 0;
int cnt = N-2;
for(int j = 1; j <= N; j++) fa[j] = j;
for(int j = 0; j < M; j++){
if(edge[j].x == i || edge[j].y == i) continue;
int fx = get(edge[j].x), fy = get(edge[j].y);
if(fx == fy) continue;
cnt–;
fa[fy] = fx;
if(edge[j].s == 0) cost[i] += edge[j].c;
}
if(cnt > 0) cost[i] = inf;
ans = max(ans, cost[i]);
}
if(ans > 0){
int flag = 0;
for(int i = 1; i <= N; i++){
if(ans == cost[i]){
printf("%s%d", flag==1?" “:”", i); flag = 1;
}
}
}else printf(“0”);
}
T1001 Battle Over Cities - Hard Version (35分)
最新推荐文章于 2023-08-23 13:22:39 发布