最小生成树
syyyyyw
acmer一枚
展开
-
poj 1789
prim就行 不同字母为距离 注意几个地方 第一 能不用string就不用string,就因为他超时了; 第二 cost[i][j] 最好是i i+1 不要是1 1这样for循环 前者跑了438 后者跑了579ms #include #include #include #include #include using namespace std; const int INF=1原创 2017-08-22 15:10:01 · 153 阅读 · 0 评论 -
poj 2485
水题 求最小生成树的最大边 改一下条件就行 prim #include #include #include #include using namespace std; const int INF=0x3f3f3f; bool used[505]; int mincost[505]; int cost[505][505]; int prim(int n) { for(int i=1;i<=原创 2017-08-22 15:54:41 · 124 阅读 · 0 评论 -
poj 3026
先bfs 再prim 看的kuangbin巨巨的解题报告 首先move会和c++的move发生冲突 ,编译器显示为ambigious; 其次学会用pair vector >p; 要用空格 make_pair pair.first pair.second 代码如下 #include #include #include #include #include using namespac原创 2017-08-22 21:07:34 · 156 阅读 · 0 评论 -
poj 1258
水题 改了改poj 2458,直接交了 #include #include #include #include using namespace std; const int INF=0x3f3f3f; bool used[505]; int mincost[505]; int cost[505][505]; int prim(int n) {原创 2017-08-22 16:20:32 · 128 阅读 · 0 评论 -
poj 2377
kruskal 最大生成树 代码如下 #include #include #include #include using namespace std; struct Node { int u,v,cost; }a[20007]; bool cmp(Node a,Node b) { return a.cost>b.cost; } int f[1007]; int Find(int原创 2018-03-08 18:45:26 · 130 阅读 · 0 评论 -
poj 2395
最小生成树的最大边 代码如下 #include #include #include #include using namespace std; struct Node { int u,v,cost; }a[10007]; bool cmp(Node a,Node b) { return a.cost<b.cost; } int f[2007]; int Find(int x)原创 2018-03-08 19:06:45 · 216 阅读 · 0 评论