結果

問題 No.1480 Many Complete Graphs
ユーザー kwm_tkwm_t
提出日時 2021-04-19 23:01:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,728 bytes
コンパイル時間 1,724 ms
コンパイル使用メモリ 175,100 KB
実行使用メモリ 16,956 KB
最終ジャッジ日時 2023-09-17 08:31:51
合計ジャッジ時間 6,057 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
11,284 KB
testcase_01 AC 7 ms
11,336 KB
testcase_02 AC 7 ms
11,340 KB
testcase_03 AC 7 ms
11,288 KB
testcase_04 AC 6 ms
11,328 KB
testcase_05 AC 6 ms
11,264 KB
testcase_06 AC 7 ms
11,524 KB
testcase_07 AC 7 ms
11,348 KB
testcase_08 AC 6 ms
11,344 KB
testcase_09 AC 7 ms
11,348 KB
testcase_10 AC 7 ms
11,348 KB
testcase_11 AC 7 ms
11,280 KB
testcase_12 AC 7 ms
11,340 KB
testcase_13 AC 17 ms
12,600 KB
testcase_14 AC 13 ms
12,064 KB
testcase_15 AC 27 ms
13,456 KB
testcase_16 AC 17 ms
12,600 KB
testcase_17 AC 18 ms
12,568 KB
testcase_18 AC 8 ms
11,560 KB
testcase_19 AC 18 ms
12,592 KB
testcase_20 AC 24 ms
13,188 KB
testcase_21 AC 19 ms
12,920 KB
testcase_22 AC 13 ms
12,056 KB
testcase_23 AC 33 ms
14,512 KB
testcase_24 AC 31 ms
14,100 KB
testcase_25 AC 49 ms
14,792 KB
testcase_26 AC 51 ms
15,336 KB
testcase_27 AC 31 ms
14,184 KB
testcase_28 AC 41 ms
16,192 KB
testcase_29 AC 42 ms
16,164 KB
testcase_30 AC 40 ms
15,748 KB
testcase_31 AC 40 ms
15,724 KB
testcase_32 AC 42 ms
16,220 KB
testcase_33 AC 40 ms
15,800 KB
testcase_34 AC 41 ms
16,136 KB
testcase_35 AC 41 ms
16,232 KB
testcase_36 AC 41 ms
16,324 KB
testcase_37 AC 40 ms
15,840 KB
testcase_38 AC 40 ms
16,164 KB
testcase_39 AC 39 ms
15,780 KB
testcase_40 AC 39 ms
15,856 KB
testcase_41 AC 39 ms
15,744 KB
testcase_42 AC 41 ms
16,148 KB
testcase_43 AC 42 ms
16,276 KB
testcase_44 AC 40 ms
15,896 KB
testcase_45 AC 42 ms
16,132 KB
testcase_46 AC 40 ms
15,812 KB
testcase_47 AC 78 ms
16,384 KB
testcase_48 AC 78 ms
16,344 KB
testcase_49 AC 78 ms
16,388 KB
testcase_50 AC 46 ms
16,096 KB
testcase_51 AC 81 ms
16,560 KB
testcase_52 AC 60 ms
16,576 KB
testcase_53 AC 61 ms
16,348 KB
testcase_54 AC 64 ms
16,284 KB
testcase_55 AC 63 ms
16,288 KB
testcase_56 AC 61 ms
16,464 KB
testcase_57 WA -
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(300005, 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