![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
最小生成树
【杰杰】
这个作者很懒,什么都没留下…
展开
-
杭电8-Ink on paper
传送门思路:prim最小生成树,克鲁斯卡尔会神奇的t掉。#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<map>#include<queue>#include<math.h>#include<vector>using namespace std;#define ll long原创 2021-08-17 21:44:20 · 263 阅读 · 0 评论 -
P2121 拆地毯
传送门#include<bits/stdc++.h>using namespace std;#define ll long longconst int mod = 998244353;struct node{ int x,y,w; friend bool operator < (node a, node b) { return a.w < b.w; }};priority_queue<node>q;int f[100010];node n原创 2021-05-22 16:40:38 · 84 阅读 · 0 评论 -
P2820 局域网
传送门思路:把那些未选择的边加在一起就行。#include<bits/stdc++.h>using namespace std;#define ll long longconst int mod = 998244353;int f[400010];int find(int x){ return f[x] == x ? x : f[x] = find(f[x]);}struct node{ int x,y,w; friend bool operator < (原创 2021-05-21 20:44:46 · 66 阅读 · 0 评论 -
P1195 口袋的天空
传送门#include<bits/stdc++.h>using namespace std;#define ll long longconst int mod = 998244353;struct node{ int u,v,w; friend bool operator < (node a, node b) { return a.w > b.w; }};priority_queue<node>q;int f[1010];int find(原创 2021-05-20 21:28:17 · 77 阅读 · 0 评论 -
P1194 买礼物
传送门思路:需要标记哪些通过优惠已经购买了,如果至少有一次是通过优惠购买的,则需要在答案上加上a,因为第一次不是通过优惠购买的。#include<bits/stdc++.h>using namespace std;#define ll long longconst int inf = 0x3f3f3f3f;int f[1010];int vis[1010];int find(int x){ return f[x] == x ? x : f[x]=find(f[x]);}原创 2021-05-19 22:16:11 · 76 阅读 · 0 评论 -
P1396 营救
传送门思路:克鲁斯卡尔最小生成树,在加入边的时候判断s与t是否已经连通即可。#include<bits/stdc++.h>using namespace std;#define ll long longconst int inf = 0x3f3f3f3f;int f[10010];int find(int x){ return f[x] == x ? x : f[x]=find(f[x]);}struct node{ int x,y; int w; friend原创 2021-05-19 21:34:27 · 52 阅读 · 0 评论 -
P4047 [JSOI2010]部落划分
传送门思路:要使划分后有k坨部落,也就是要进行两两合并n-k次,合并后再找到最近两坨部落间的距离即为答案。#include<bits/stdc++.h>using namespace std;#define ll long longconst int inf = 0x3f3f3f3f;struct node{ int a,b; double t; friend bool operator < (node a, node b) { return a.t >原创 2021-05-15 22:30:24 · 75 阅读 · 0 评论 -
P2330 [SCOI2005]繁忙的都市
传送门思路:本质上还是最小生成树模板。#include<bits/stdc++.h>using namespace std;#define ll long longstruct node{ int x,y; int c; friend bool operator < (node a, node b) { return a.c > b.c; }};priority_queue<node>q;int f[310];int find(int原创 2021-05-14 22:41:01 · 90 阅读 · 0 评论 -
P1546 [USACO3.1]最短网络 Agri-Net
传送门#include<bits/stdc++.h>using namespace std;#define ll long longint g[110][110];int sum;struct node{ int x,y; int t; friend bool operator < (node a, node b) { return a.t > b.t; }};priority_queue<node>q;int f[110];int f原创 2021-05-14 22:26:39 · 192 阅读 · 0 评论 -
P1991 无线通讯网
传送门思路:把生成最小生成树的最大边权值用卫星链接就行。#include<bits/stdc++.h>using namespace std;#define ll long longstruct node{ double x,y,t; friend bool operator < (node a, node b) { return a.t>b.t; }};priority_queue<node>q;node g[510];node now原创 2021-05-12 23:41:20 · 71 阅读 · 0 评论 -
P2872 [USACO07DEC]Building Roads S
传送门思路:将已有的道路加入到一个集合中,并将所有边加入到优先队列当中,最后在原有图的基础上找最小生成树。#include <bits/stdc++.h>using namespace std;#define ll long longstruct node{ ll x,y; double t; friend bool operator < (node a, node b) { return a.t > b.t; }};priority_queue<原创 2021-05-07 19:26:59 · 122 阅读 · 0 评论 -
最小生成树
传送门#include<bits/stdc++.h>using namespace std;#define ll long long struct node{ int x,y; int t; friend bool operator < (node a, node b) { return a.t > b.t; }};int f[5010];int find(int x){ return f[x] == x ? x:f[x]=find(f[x]);}原创 2021-05-01 19:52:54 · 46 阅读 · 0 评论