結果
問題 | No.1480 Many Complete Graphs |
ユーザー | se1ka2 |
提出日時 | 2021-04-16 21:15:42 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,113 bytes |
コンパイル時間 | 926 ms |
コンパイル使用メモリ | 86,892 KB |
実行使用メモリ | 23,808 KB |
最終ジャッジ日時 | 2023-09-16 02:53:03 |
合計ジャッジ時間 | 5,599 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,680 KB |
testcase_01 | AC | 3 ms
5,676 KB |
testcase_02 | AC | 3 ms
5,776 KB |
testcase_03 | AC | 3 ms
5,704 KB |
testcase_04 | AC | 2 ms
5,924 KB |
testcase_05 | AC | 3 ms
6,268 KB |
testcase_06 | AC | 2 ms
5,700 KB |
testcase_07 | AC | 3 ms
5,696 KB |
testcase_08 | AC | 3 ms
6,020 KB |
testcase_09 | AC | 3 ms
6,232 KB |
testcase_10 | AC | 5 ms
5,964 KB |
testcase_11 | AC | 3 ms
5,796 KB |
testcase_12 | AC | 3 ms
6,240 KB |
testcase_13 | AC | 19 ms
10,636 KB |
testcase_14 | AC | 16 ms
8,656 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 6 ms
6,260 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 24 ms
11,424 KB |
testcase_22 | AC | 15 ms
8,468 KB |
testcase_23 | AC | 48 ms
15,916 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | AC | 53 ms
16,812 KB |
testcase_43 | AC | 51 ms
16,624 KB |
testcase_44 | AC | 52 ms
16,832 KB |
testcase_45 | AC | 53 ms
17,448 KB |
testcase_46 | AC | 54 ms
16,816 KB |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | AC | 70 ms
19,616 KB |
testcase_51 | AC | 69 ms
20,072 KB |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | AC | 57 ms
17,364 KB |
testcase_55 | AC | 58 ms
17,720 KB |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | AC | 88 ms
23,808 KB |
evil_aftercontest.txt | AC | 171 ms
42,584 KB |
ソースコード
#include <iostream> #include <queue> using namespace std; typedef long long ll; template <typename T> struct Edge { int to; T cost; }; template <typename T> struct WeightedGraph { int n; std::vector<std::vector<Edge<T>>> g; WeightedGraph(){} WeightedGraph(int n) : n(n){ g.resize(n); } void add_edge(int from, int to, T cost){ g[from].push_back((Edge<T>){to, cost}); } }; template <typename T> std::vector<T> dijkstra(WeightedGraph<T> &g, int s){ int n = g.n; std::vector<T> d(n); fill(d.begin(), d.end(), -2); std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> que; d[s] = 0; que.push(std::pair<T, int>(0, s)); while(que.size()){ std::pair<T, int> p = que.top(); que.pop(); int u = p.second; if(d[u] < p.first) continue; for(Edge<T> &e : g.g[u]){ int v = e.to; if(d[v] == -2 || d[v] > d[u] + e.cost){ d[v] = d[u] + e.cost; que.push(std::pair<T, int>(d[v], v)); } } } return d; } int main() { int n, m; cin >> n >> m; int k[100005]; ll c[100005]; vector<int> s[100005]; int l = 0; for(int i = 0; i < m; i++){ cin >> k[i] >> c[i]; l += k[i]; s[i].resize(k[i]); for(int j = 0; j < k[i]; j++) cin >> s[i][j]; } WeightedGraph<ll> g(l + m * 2 + 2); int id = m * 2; for(int i = 0; i < m; i++){ for(int j = 0; j < k[i]; j++){ g.add_edge(id, i * 2, (s[i][j] + 1) / 2 * 2 + c[i]); g.add_edge(i * 2, id, (s[i][j] + 1) / 2 * 2 + c[i]); if(s[i][j] % 2){ g.add_edge(id, i * 2 + 1, s[i][j] + c[i]); g.add_edge(i * 2 + 1, id, s[i][j] + c[i]); } if(s[i][j] == 1) g.add_edge(l + m * 2, id, 0); if(s[i][j] == n) g.add_edge(id, l + m * 2 + 1, 0); id++; } } vector<ll> d = dijkstra(g, l + m * 2); cout << d[l + m * 2 + 1] / 2 << endl; }