結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー 夜
提出日時 2020-12-17 16:41:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,546 bytes
コンパイル時間 1,036 ms
コンパイル使用メモリ 104,416 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 06:59:41
合計ジャッジ時間 7,527 ms
ジャッジサーバーID
(参考情報)
judge10 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 3 ms
4,348 KB
testcase_21 WA -
testcase_22 AC 2 ms
4,348 KB
testcase_23 RE -
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 AC 3 ms
4,348 KB
testcase_40 RE -
testcase_41 WA -
testcase_42 AC 2 ms
4,348 KB
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 WA -
testcase_51 WA -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
vector<vector<pair<int,long long>>> vec(2020);
int u[2020], v[2020];
long long w[2020];
long long mi[2020];
int main() {
	bool t;
	cin >> t;
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> u[i] >> v[i] >> w[i];
		if (!t) {
			vec[v[i]].emplace_back(make_pair(u[i], w[i]));
		}
		vec[u[i]].emplace_back(make_pair(v[i], w[i]));
	}
	long long ans = 10000000000000007;
	for (int i = 0; i < m; i++) {
		priority_queue<pair<long long, int>,vector<pair<long long,int>>,greater<pair<long long,int>>> que;
		for (int j = 1; j <= n; j++) {
			mi[j] = 10000000000000007;
		}
		que.push(make_pair(0, v[i]));
		mi[v[i]] = 0;
		while (!que.empty()) {
			long long x = que.top().first;
			int y = que.top().second;
			que.pop();
			for (int j = 0; j < vec[y].size(); j++) {
				if (y == v[i] && vec[y][j].first == u[i]) {
					continue;
				}
				if (y == u[i] && vec[y][j].first == v[i]) {
					continue;
				}
				if (mi[vec[y][j].second] > x + vec[y][j].second) {
					mi[vec[y][j].second] = x + vec[y][j].second;
					que.push(make_pair(x + vec[y][j].second, vec[y][j].first));
				}
			}
		}
		if (ans > w[i] + mi[u[i]]) {
			ans = w[i] + mi[u[i]];
		}
	}
	if (ans == 10000000000000007) {
		cout << -1 << endl;
		return 0;
	}
	cout << ans << endl;
}
0