L2-036 網紅點打卡攻略

YuKiCheng發表於2024-03-22

沒有AC,沒有用到每個地點只能打卡一次的限制條件。
錯誤版本:

#include <bits/stdc++.h>
using namespace std;
int edges[210][210], fangan[2000][2000];
int minspend = INT_MAX;
int idx = 0;
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		edges[a][b] = edges[b][a] = c;
	}
	int t;
	cin >> t;
	for (int i = 1; i <= t; i++) {//第i種方案
		cin >> fangan[i][0];
		for (int j = 1; j <= fangan[i][0]; j++) {
			cin >> fangan[i][j];
		}
	}
	int res = 0;//可行方案
	for (int i = 1; i <= t; i++) {
		int spend = 0;
		if (fangan[i][0] != n) continue;
		//檢查方案
		//是否能從家出發最後返回
		if (edges[0][fangan[i][1]] == 0 || edges[0][fangan[i][6]] == 0) continue;
		spend += edges[0][fangan[i][1]];
		spend += edges[0][fangan[i][6]];
		int j = 2;
		for (j = 2; j <= 6; j++) {
			if (edges[fangan[i][j]][fangan[i][j - 1]] == 0) {
				break;//不可達
			}
			spend += edges[fangan[i][j]][fangan[i][j - 1]];
		}
		if (j > fangan[i][0]) {
			res++;
			if (spend < minspend) {
				minspend = spend;
				idx = i;
			}
		}
	}
	cout << res << '\n';
	cout << idx << " " << minspend << '\n';
	return 0;
}

相關文章