結果

問題 No.1480 Many Complete Graphs
ユーザー 👑 jupirojupiro
提出日時 2021-04-16 21:33:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 998 ms / 2,000 ms
コード長 1,768 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 128,168 KB
実行使用メモリ 14,108 KB
最終ジャッジ日時 2023-09-16 02:54:28
合計ジャッジ時間 9,189 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 11 ms
6,380 KB
testcase_14 AC 8 ms
5,072 KB
testcase_15 AC 24 ms
7,856 KB
testcase_16 AC 15 ms
7,080 KB
testcase_17 AC 13 ms
6,384 KB
testcase_18 AC 5 ms
5,688 KB
testcase_19 AC 14 ms
6,220 KB
testcase_20 AC 19 ms
6,260 KB
testcase_21 AC 11 ms
5,692 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 24 ms
8,512 KB
testcase_24 AC 27 ms
6,200 KB
testcase_25 AC 47 ms
9,380 KB
testcase_26 AC 47 ms
10,440 KB
testcase_27 AC 30 ms
6,320 KB
testcase_28 AC 36 ms
10,788 KB
testcase_29 AC 38 ms
10,768 KB
testcase_30 AC 42 ms
11,708 KB
testcase_31 AC 43 ms
11,816 KB
testcase_32 AC 43 ms
11,804 KB
testcase_33 AC 37 ms
10,788 KB
testcase_34 AC 36 ms
10,832 KB
testcase_35 AC 42 ms
11,832 KB
testcase_36 AC 41 ms
11,932 KB
testcase_37 AC 37 ms
10,752 KB
testcase_38 AC 35 ms
10,852 KB
testcase_39 AC 36 ms
10,692 KB
testcase_40 AC 43 ms
11,736 KB
testcase_41 AC 36 ms
10,772 KB
testcase_42 AC 42 ms
11,768 KB
testcase_43 AC 52 ms
14,108 KB
testcase_44 AC 42 ms
11,816 KB
testcase_45 AC 37 ms
10,664 KB
testcase_46 AC 36 ms
10,892 KB
testcase_47 AC 57 ms
10,704 KB
testcase_48 AC 54 ms
10,676 KB
testcase_49 AC 56 ms
10,772 KB
testcase_50 AC 34 ms
10,332 KB
testcase_51 AC 58 ms
10,820 KB
testcase_52 AC 44 ms
10,656 KB
testcase_53 AC 42 ms
10,728 KB
testcase_54 AC 43 ms
10,760 KB
testcase_55 AC 41 ms
10,744 KB
testcase_56 AC 53 ms
11,696 KB
testcase_57 AC 31 ms
9,376 KB
testcase_58 AC 998 ms
8,616 KB
evil_aftercontest.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
  else
    cout << 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;
}
0