1 条题解
-
0
C++ :
#include <cstdio> #include <iostream> #include <cstring> #include <cstdlib> #include <algorithm> #include <cmath> #include <ctime> #include <climits> #include <set> #include <map> #include <queue> using namespace std; int n,m; struct NODE{ int to; int next; int va; }A[2005]; int len=0; int head[1005]; bool exist[1005]; int dis[1005]; int my_max=0; queue<int>T; void Build(int a,int b,int c){ len++; A[len].to=b; A[len].va=c; A[len].next=head[a]; head[a]=len; } void init(){ scanf("%d%d",&n,&m); int a,b,c; for(int i=1;i<=m;i++){ // cout<<a<<" "<<b<<endl; scanf("%d%d%d",&a,&b,&c); Build(a,b,c); Build(b,a,c); } } void SPFA(int x,int tot){ my_max=my_max>tot? my_max:tot; for(int i=head[x];i;i=A[i].next){ int y=A[i].to; if(exist[y]==false)exist[y]=true,SPFA(y,tot+A[i].va); } exist[x]=false; } void work(){ for(int i=1;i<=n;i++){ exist[i]=true; SPFA(i,0); exist[i]=false; // memset(exist,0,sizeof(exist)); } printf("%d\n",my_max); } int main(){ // freopen("1.in","r",stdin); //freopen("walk.in","r",stdin); // freopen("walk.out","w",stdout); init(); work(); // cout<<(double)clock() / CLOCKS_PER_SEC<<endl; // while(1); fclose(stdin); fclose(stdout); }
- 1
信息
- ID
- 964
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者