dalao来看看吧!!!为啥都是Disconnected???

P3366 【模板】最小生成树

啊啊啊没了 没错啊
by 三氯甲硅烷 @ 2019-10-12 23:02:48


ok了 故障已排除 31行 的 = 应为 == 贴上好看的正解叭 ```cpp #include<bits/stdc++.h> #define Disconnected "orz" using namespace std; const int _EGDE__NUM_ = 10000; const int _NODE__NUM_ = 1000; struct _EDGE_ { float _U_ = 0; float _V_ = 0; float _W_ = 0; bool operator < (const _EDGE_ &comp) const { return _W_ < comp._W_; } }; _EDGE_ edge[_EGDE__NUM_]; int disJoint[_NODE__NUM_]; void input(void); void initDisJoint(int nn); inline int find(int x); pair< vector< int > , int > kruskal(void); int nodeNum,edgeNum; int main() { input(); initDisJoint(nodeNum); pair< vector< int > , int > output = kruskal(); if(output.second == -1) { cout << Disconnected << endl; } else { cout << output.second << endl; } #undef Disconnected return 0; } void initDisJoint(int nn) { for(int i = 1;i <= nn;i ++) { disJoint[i] = i; } return; } void input(void) { cin >> nodeNum >> edgeNum; for(int i = 0;i < edgeNum;i ++) { cin >> edge[i]._U_ >> edge[i]._V_ >> edge[i]._W_; } return ; } inline int find(int x) { while(x != disJoint[x]) { x = disJoint[x] = disJoint[disJoint[x]]; } return x; } pair< vector< int > , int > kruskal(void) { sort(edge,edge+edgeNum); pair< vector< int > , int > ansEdge; ansEdge.second = -1; int nodeU,nodeV; float ans = 0; int edgeCount = 0; for(int i = 0;i < edgeNum;i ++) { nodeU = find(edge[i]._U_); nodeV = find(edge[i]._V_); if(nodeU == nodeV) { continue; } ans += edge[i]._W_; ansEdge.first.push_back(i); disJoint[nodeV] = disJoint[nodeU]; edgeCount ++; if(edgeCount == nodeNum - 1) { ansEdge.second = ans; break; } } return ansEdge; } ```
by 三氯甲硅烷 @ 2019-10-12 23:24:59


00
by 榴莲菌 @ 2019-10-29 20:25:06


|