結果
問題 | No.1480 Many Complete Graphs |
ユーザー |
|
提出日時 | 2021-04-16 21:33:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,859 ms / 2,000 ms |
コード長 | 1,768 bytes |
コンパイル時間 | 1,387 ms |
コンパイル使用メモリ | 123,860 KB |
最終ジャッジ日時 | 2025-01-20 19:33:24 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 TLE * 1 |
ソースコード
#include <iostream>#include <string>#include <algorithm>#include <vector>#include <queue>#include <utility>#include <tuple>#include <cmath>#include <numeric>#include <set>#include <map>#include <array>#include <complex>#include <iomanip>#include <cassert>#include <random>using ll = long long;using std::cin;using std::cout;using std::endl;template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }const int inf = (int)1e9 + 7;const long long INF = 1LL << 60;void solve(){int n, m; cin >> n >> m;std::vector<std::vector<int>> a(m), L(n);std::vector<ll> c(m);std::vector<int> fin(m, n);for (int i = 0; i < m; ++i){int k; cin >> k >> c[i];auto &v = a[i];v.resize(k);for (int j = 0; j < k; ++j){cin >> v[j];v[j] -= 1;L[v[j]].emplace_back(i);}}std::priority_queue<std::pair<ll, int>, std::vector<std::pair<ll, int>>, std::greater<>> pq;std::vector<ll> d(n, INF);d[0] = 0;pq.emplace(0, 0);while(not pq.empty()){const auto [dist, cur] = pq.top();pq.pop();if(dist > d[cur])continue;for(const auto &e : L[cur]){if(fin[e] <= cur)continue;fin[e] = cur;auto &v = a[e];for(const auto &to : v){if(chmin(d[to], d[cur] + (cur + to + 2 + 1) / 2 + c[e])){pq.emplace(d[to], to);}}}}if(d[n - 1] == INF)cout << -1 << "\n";elsecout << d[n - 1] << "\n";}int main(){std::cin.tie(nullptr);std::ios::sync_with_stdio(false);int kkt = 1;//cin >> kkt;while(kkt--)solve();return 0;}