Main topic
Give some edges, each with a side right and a color. A spanning tree with a need white edge is now required for the minimum edge. Output this edge right.
Ideas
Add a weight to the white edge so that the white edge can be artificially changed to appear in the smallest spanning tree. This thing obviously can be two points. Then take the minimum value to get it.
CODE
#define _crt_secure_no_warnings#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 100010using namespace STD;structedge{intx, y, length, col;BOOL operator< (ConstEdge &a)Const{if(length = = a.length)returnCol > a.col;returnLength < A.length; }voidRead () {scanf("%d%d%d%d", &x, &y, &length, &col); ++x, ++y; Col ^=1; }}edge[max];intPoints, edges, need;intFather[max];intFind (intx) {if(Father[x] = = x)returnXreturnFATHER[X] = Find (Father[x]);}inlinepair<int,int> MST () { for(inti =1; I <= points; ++i) Father[i] = i; pair<int,int> Re (0,0); Sort (Edge +1, Edge + edges +1); for(inti =1; I <= edges; ++i) {intFX = Find (edge[i].x), FY = find (EDGE[I].Y);if(FX! = FY) {Father[fy] = FX; Re.second + = Edge[i].col; Re.first + = Edge[i].length; } }returnRe;}intMain () {Cin>> points >> edges >> need; for(inti =1; I <= edges; ++i) Edge[i]. Read ();intL =- the, r = the, ans; while(L <= R) {intMid = (L + r) >>1; for(inti =1; I <= edges; ++i) Edge[i].length + = Edge[i].col * MID;intWhite = MST (). Second; for(inti =1; I <= edges; ++i) Edge[i].length-= Edge[i].col * MID;if(White >= need) L = mid +1, ans = mid;ElseR = Mid-1; } for(inti =1; I <= edges; ++i) Edge[i].length + = Edge[i].col * ans;cout<< MST (). First-need * ans << endl;return 0;}
Bzoj 2654 Tree binary + minimum spanning trees