PAT L2-036. 网红点打卡攻略
原题链接
简单
作者:
青丝蛊
,
2021-04-10 14:43:51
,
所有人可见
,
阅读 322
#include <bits/stdc++.h>
using namespace std;
int v[210][210];
int n, m;
int main()
{
cin >> n >> m;
while (m--)
{
int a, b, c; cin >> a >> b >> c;
v[a][b] = v[b][a] = c;
}
cin >> m;
int cnt = 0, MIN = 1e9, MIN_N = 1;
for (int i = 1; i <= m; i++)
{
int k;
cin >> k;
int a[k];
for (auto &c : a) cin >> c;
set<int> se(a, a + k);
bool f = true;
for (int j = 0; j < k - 1; j++) if (!v[a[j]][a[j + 1]]) { f = false; break; }
// 每个网红点打卡仅一次,并且能从家到第一个打卡点和从最后一个打卡点回家,所有路都连通
if (k != n || se.size() != n || !v[0][a[0]] || !v[a[k - 1]][0] || !f) continue;
cnt++;
int sum = v[0][a[0]] + v[a[k - 1]][0];
for (int j = 0; j < k - 1; j++) sum += v[a[j]][a[j + 1]];
if (sum < MIN)
{
MIN = sum;
MIN_N = i;
}
}
cout << cnt << endl;
cout << MIN_N << ' ' << MIN << endl;
return 0;
}