当前位置: 代码迷 >> 综合 >> PAT 甲级 1150 PAT Ranking 个人错误总结
  详细解决方案

PAT 甲级 1150 PAT Ranking 个人错误总结

热度:61   发布时间:2024-02-13 15:49:23.0

一开始没看懂题,还以为是dp旅行商问题。。

#include<bits/stdc++.h>
using namespace std;
bool flag[201];
int llist[201][201];
int main(){int n,m;cin>>n>>m;int a,b,l;for(int i=0;i<m;i++){cin>>a>>b>>l;llist[a][b]=l;llist[b][a]=l;}int k;cin>>k;int minn=99999999,tag;for(int j=1;j<=k;j++){int num;cin>>num;int sum=0,temp1,temp2;bool flag1=false,flag2=false;fill(flag,flag+201,false);cin>>temp1;int first=temp1;flag[temp1]=true;for(int i=2;i<=num;i++){cin>>temp2;flag[temp2]=true;if(llist[temp1][temp2]==0)flag1=true;else sum+=llist[temp1][temp2];temp1=temp2;}for(int i=1;i<=n;i++){if(flag[i]==false)flag2=true;}if(first!=temp1||flag2){printf("Path %d: %d (Not a TS cycle)\n",j,sum);continue;}if(flag1){printf("Path %d: NA (Not a TS cycle)\n",j,sum);continue;}if(num!=n+1){printf("Path %d: %d (TS cycle)\n",j,sum);if(sum<minn){minn=sum;tag=j;}continue;}printf("Path %d: %d (TS simple cycle)\n",j,sum);if(sum<minn){minn=sum;tag=j;}	}printf("Shortest Dist(%d) = %d",tag,minn);return 0;
}
  相关解决方案