結果

問題 No.1480 Many Complete Graphs
ユーザー kwm_tkwm_t
提出日時 2021-04-19 23:01:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,726 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 174,332 KB
実行使用メモリ 15,132 KB
最終ジャッジ日時 2023-09-17 08:31:45
合計ジャッジ時間 13,335 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,464 KB
testcase_01 AC 5 ms
10,368 KB
testcase_02 AC 6 ms
10,364 KB
testcase_03 AC 6 ms
10,380 KB
testcase_04 AC 6 ms
10,368 KB
testcase_05 AC 5 ms
10,532 KB
testcase_06 AC 5 ms
10,436 KB
testcase_07 AC 6 ms
10,400 KB
testcase_08 AC 6 ms
10,416 KB
testcase_09 AC 6 ms
10,508 KB
testcase_10 AC 6 ms
10,612 KB
testcase_11 AC 5 ms
10,392 KB
testcase_12 AC 5 ms
10,576 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 WA -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 WA -
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 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 WA -
evil_aftercontest.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
struct Edge {
	int to, cost;
	Edge(int _to, int _cost) :to(_to), cost(_cost) {}
};
vector<Edge>g[300005];

typedef pair<long long, int> P;
long long dikstra(int st, int ed) {
	vector<int> D(2000, INF);
	priority_queue<P, vector<P>, greater<P> > q;//小さいもの順
	q.emplace(0, st);
	D[st] = 0;
	while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		long long cost = tmp.first;
		long long pos = tmp.second;
		if (cost > D[pos]) continue;
		for (Edge e : g[pos]) {
			if (cost + e.cost < D[e.to]) {
				D[e.to] = e.cost + cost;
				q.emplace(D[e.to], e.to);
			}
		}
	}
	if (INF == D[ed]) D[ed] = -1;
	else D[ed] /= 2;
	return D[ed];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m; cin >> n >> m;
	rep(i, m) {
		int k; cin >> k;
		int c; cin >> c;
		int u = n + 2 * i;
		int v = n + 2 * i + 1;
		rep(j, k) {
			int s; cin >> s; s--;
			if (0 == s % 2) {
				g[u].emplace_back(s, c + s + 1);
				g[s].emplace_back(u, c + s + 1);
			}
			else {
				g[v].emplace_back(s, c + s + 1);
				g[s].emplace_back(v, c + s + 1);
			}
		}
		g[u].emplace_back(v, 1);
		g[v].emplace_back(u, 1);
	}
	cout << dikstra(0, n - 1) << endl;
	return 0;
}
0