vc编译通过,但提交到九度oj编译就不通过,求帮忙看看编译信息
题目描述: 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可)。经过调查评估,得到的统计表中列出了有可能建设公路的若干条道路的成本。现请你编写程序,计算出全省畅通需要的最低成本。
输入:
测试输入包含若干测试用例。每个测试用例的第1行给出评估的道路条数 N、村庄数目M (N, M < =100 );随后的 N 行对应村庄间道路的成本,每行给出一对正整数,分别是两个村庄的编号,以及此两村庄间道路的成本(也是正整数)。为简单起见,村庄从1到M编号。当N为0时,全部输入结束,相应的结果不要输出。
输出:
对每个测试用例,在1行里输出全省畅通需要的最低成本。若统计数据不足以保证畅通,则输出“?”。
样例输入:
3 3
1 2 1
1 3 2
2 3 4
1 3
2 3 2
0 100样例输出:
3
?
程序代码:
#include <stdio.h> #include <algorithm> using namespace std; int Tree[101]; int findRoot(int x){ if(Tree[x]==-1) return x; else{ int tmp=findRoot(Tree[x]); Tree[x]=tmp; return tmp; } } struct Edge{ int a,b; int cost; bool operator < (const Edge &A){ return cost<A.cost; } }edge[6000]; int main(){ int n,m,i; while(scanf("%d%d",&n,&m)!=EOF&&n!=0){ for(i=1;i<=n;i++){ scanf("%d%d%d",&edge[i].a,&edge[i].b,&edge[i].cost); } sort(edge+1,edge+n+1); for(i=1;i<=m;i++) Tree[i]=-1; int ans=0,size=1; for(i=1;i<=n;i++){ int a=findRoot(edge[i].a); int b=findRoot(edge[i].b); if(a!=b){ Tree[a]=b; ans+=edge[i].cost; size++; } } if(size==n) printf("%d\n",ans); else printf("?\n"); } return 0; }主体思路就是用Kruskal求最小生成树。
下面是编译信息,不太看得懂,求指点
Main.cc: In function ‘int main()’:
Main.cc:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
In file included from /usr/include/c++/4.4/algorithm:62,
from Main.cc:2:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&) [with _Tp = Edge]’:
/usr/include/c++/4.4/bits/stl_algo.h:2268: instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = Edge*, _Size = long int]’
/usr/include/c++/4.4/bits/stl_algo.h:5220: instantiated from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = Edge*]’
Main.cc:26: instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:89: error: passing ‘const Edge’ as ‘this’ argument of ‘bool Edge::operator<(const Edge&)’ discards qualifiers
/usr/include/c++/4.4/bits/stl_algo.h:90: error: passing ‘const Edge’ as ‘this’ argument of ‘bool Edge::operator<(const Edge&)’ discards qualifiers
/usr/include/c++/4.4/bits/stl_algo.h:92: error: passing ‘const Edge’ as ‘this’ argument of ‘bool Edge::operator<(const Edge&)’ discards qualifiers
/usr/include/c++/4.4/bits/stl_algo.h:96: error: passing ‘const Edge’ as ‘this’ argument of ‘bool Edge::operator<(const Edge&)’ discards qualifiers
/usr/include/c++/4.4/bits/stl_algo.h:98: error: passing ‘const Edge’ as ‘this’ argument of ‘bool Edge::operator<(const Edge&)’ discards qualifiers