#include<bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 210;
int g[N][N], n, m, k, cnt, res = inf, res_id;
bool vis[N]; //标记是否访问过
int s[N]; //当前旅游路线
int main(){
cin >> n >> m;
memset(g, 0x3f, sizeof(g));//默认初始化为最大值
while(m--){
int u, v, c; cin >> u >> v >> c;
g[u][v] = g[v][u] = min(g[u][v], c); //避免重边
}
cin >> k;
for(int id = 1; id <= k; id ++ ){
int nn; cin >> nn;
memset(vis, false, sizeof(vis));
for(int i = 1; i <= nn; i ++ ) cin >> s[i];
if(nn != n) continue; //旅游点不满n个
bool flag = true;
int u = 0, sum = 0;
for(int i = 1; i <= nn; i ++ ){
int v = s[i];
if(vis[v] || g[u][v] == inf){
//如果被访问过 或者 无法到达
flag = false;
break;
}
sum += g[u][v];
vis[v] = true;
u = v;
}
if(g[u][0] == inf) flag = false; //最后的点无法到家
if(flag){
sum += g[u][0];
cnt ++ ; //合法旅游路线+1
if(sum < res){ //更新答案,保证了注意这里等于不更新即保证了其输出序号最小
res = sum;
res_id = id;
}
}
}
cout << cnt << endl;//每个网红点均一次且转一圈仍可到家的个数
cout << res_id << ' ' << res << endl;//满足攻略的最小花费
return 0;
}
!!!看懂题后真就纯纯模拟题(用邻接矩阵存储图)