Problem DescriptionAn abandoned country has n(n≤100000)villages which are numbered from 1 to n. Since abandoned for a long time, the roads need to be re-built. There are m(m≤1000000)roads to be re-built, the length of each road is wi(wi≤1000000). Guaran…
A - The order of a Tree
根据二叉搜索树的性质,我们知道key[Lchild[r]]≤key[r]≤key[Rchild[r]],所以LDR遍历插入一定是同结构的最小字典序二叉搜索树 指针版:
#include <iostream>
#include <cstdlib>
using namespace s…
问的是:即最早什么时候任意两条村庄都存在至少一条修复完成的道路(可以由多条公路连成一条道路)。(可以多条同时一起修咯)
ACcode:
kruskal():
#include<bits/stdc.h>
using namespace std;
#define int lon…
题目描述 In an episode of the Dick Van Dyke show, little Richie connects the freckles on his Dads back to form a picture of the Liberty Bell. Alas, one of the freckles turns out to be a scar, so his Ripleys engagement falls through. Consider Dicks bac…
用最小生成树中的Kruskal算法解决。
代码如下:
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn1e45;
struct E
{int f,t;int wei;
}edge[maxn];
int fa[105];bool cmp(E x, E y)
{return x.wei…
算法基础简介 - OI Wiki (oi-wiki.org) 文章目录1. 数据结构介绍1.1 什么是数据结构1.2 数据结构分类2. 链表、栈、队列:略3. 哈希表:略4. 树4.1 二叉树4.2 B 树与 B 树4.3 哈夫曼(霍夫曼)树:Huffman Tree4.4 线段树&a…
目录 1.概述2.代码实现2.1.邻接矩阵存储图2.2.邻接表存储图2.3.测试 3.应用 1.概述
(1)在一给定的无向图 G (V, E) 中,(u, v) 代表连接顶点 u 与顶点 v 的边,而 w(u, v) 代表此边的权重,若存在 T 为 E 的子集且为无循…
P3366 【模板】最小生成树
一道模板题,prim算法就可以过,krustal算法也是可以的嗷 prim算法
#include <bits/stdc.h>
using namespace std;
const int N 5010;
const int INF 0x3f3f3f3f;
int n, m;
int g[N][N];
int dist[N];
bool st[N];
in…
最短网络
题目http://ybt.ssoier.cn:8088/problem_show.php?pid1350
#include<bits/stdc.h>
using namespace std;
const int N110;
int w[N][N];
bool st[N];
int dist[N];
int n,res0;
void prim()
{memset(dist,0x3f,sizeof dist);dist[1]0;//初始化第一个点到自己…
最小生成树
在一给定的无向图G (V, E) 中,(u, v) 代表连接顶点 u 与顶点 v 的边,而 w(u, v) 代表此边的权重,若存在 T 为 E 的子集,使得 w(T) 最小,则此 T 为 G 的最小生成树。最小生成树可以用kruskal(克鲁斯卡尔)算法或prim(普里姆&#…