結果

問題 No.1480 Many Complete Graphs
ユーザー kwm_tkwm_t
提出日時 2021-04-19 23:02:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,736 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 175,084 KB
実行使用メモリ 18,076 KB
最終ジャッジ日時 2023-09-17 08:31:58
合計ジャッジ時間 6,131 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
12,392 KB
testcase_01 AC 8 ms
12,340 KB
testcase_02 AC 8 ms
12,340 KB
testcase_03 AC 6 ms
12,288 KB
testcase_04 AC 8 ms
12,396 KB
testcase_05 AC 6 ms
12,296 KB
testcase_06 AC 7 ms
12,356 KB
testcase_07 AC 7 ms
12,392 KB
testcase_08 AC 7 ms
12,308 KB
testcase_09 AC 7 ms
12,412 KB
testcase_10 AC 8 ms
12,400 KB
testcase_11 AC 7 ms
12,360 KB
testcase_12 AC 8 ms
12,400 KB
testcase_13 AC 17 ms
13,920 KB
testcase_14 AC 15 ms
13,396 KB
testcase_15 AC 29 ms
14,876 KB
testcase_16 AC 19 ms
13,764 KB
testcase_17 AC 19 ms
13,964 KB
testcase_18 AC 9 ms
12,776 KB
testcase_19 AC 19 ms
13,840 KB
testcase_20 AC 25 ms
14,400 KB
testcase_21 AC 20 ms
13,984 KB
testcase_22 AC 14 ms
13,100 KB
testcase_23 AC 33 ms
15,556 KB
testcase_24 AC 31 ms
15,312 KB
testcase_25 AC 49 ms
16,008 KB
testcase_26 AC 52 ms
16,644 KB
testcase_27 AC 34 ms
15,408 KB
testcase_28 AC 42 ms
17,396 KB
testcase_29 AC 44 ms
17,316 KB
testcase_30 AC 41 ms
16,924 KB
testcase_31 AC 41 ms
17,004 KB
testcase_32 AC 42 ms
17,308 KB
testcase_33 AC 41 ms
16,948 KB
testcase_34 AC 42 ms
17,352 KB
testcase_35 AC 42 ms
17,356 KB
testcase_36 AC 42 ms
17,344 KB
testcase_37 AC 42 ms
17,088 KB
testcase_38 AC 43 ms
17,424 KB
testcase_39 AC 42 ms
16,976 KB
testcase_40 AC 41 ms
16,988 KB
testcase_41 AC 41 ms
17,032 KB
testcase_42 AC 42 ms
17,316 KB
testcase_43 AC 41 ms
17,336 KB
testcase_44 AC 40 ms
16,924 KB
testcase_45 AC 42 ms
17,288 KB
testcase_46 AC 41 ms
17,184 KB
testcase_47 AC 88 ms
17,620 KB
testcase_48 AC 87 ms
17,548 KB
testcase_49 AC 85 ms
17,552 KB
testcase_50 AC 49 ms
17,084 KB
testcase_51 AC 87 ms
17,616 KB
testcase_52 AC 67 ms
17,628 KB
testcase_53 AC 67 ms
17,524 KB
testcase_54 AC 66 ms
17,620 KB
testcase_55 AC 67 ms
17,516 KB
testcase_56 AC 66 ms
17,512 KB
testcase_57 AC 41 ms
17,148 KB
testcase_58 AC 43 ms
18,076 KB
evil_aftercontest.txt AC 80 ms
23,608 KB
権限があれば一括ダウンロードができます

ソースコード

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<long long> D(300005, LINF);
	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 (LINF == 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