1150

#include 
#include 
#include 
using namespace std;
int G[220][220];
int main(){
	int n,m,u,v,c,k;
	scanf("%d %d",&n,&m);
	for(int i = 0; i < m; i++){
		scanf("%d %d %d",&u,&v,&c);
		G[u][v] = G[v][u] = c;
	}
	scanf("%d",&k);
	int total = 100010,p = -1;
	for(int i = 1; i <= k; i++){
		scanf("%d",&u);
		vector t;
		int h[220]= {0}; 
		int flag = 1;
		for(int j = 0; j < u; j++){
			scanf("%d",&v);
			t.push_back(v);
			h[v]++;
		}
		for(int i = 1; i <= n; i++){
			if(h[i] == 0){
				flag = 3;break;
			}
		}
		if(u > n+1) flag = 2;
		else if(u < n+1 || t[0] != t[u-1]) flag = 3;
		int s = 0;
		for(int j = 1; j < u; j++){
			if(G[t[j]][t[j-1]] == 0){
				printf("Path %d: NA (Not a TS cycle)\n",i);
				s = -1;
				break;
			}
			else s += G[t[j]][t[j-1]];
		}
		if(flag != 3 && s < total &&s!= -1){
			total = s;
			p = i;
		}
		if(s > 0){
			if(flag == 1) printf("Path %d: %d (TS simple cycle)\n",i,s);
			else if(flag == 2) printf("Path %d: %d (TS cycle)\n",i,s);
			else printf("Path %d: %d (Not a TS cycle)\n",i,s);
		}
	}
	printf("Shortest Dist(%d) = %d",p,total);
	return 0;
}

没考虑  flag= 3时 没能遍历所有的点  用set 既去重又能判断 覆盖的点数

你可能感兴趣的:(1150)