QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#119153#5506. Hyperloophos_lyricAC ✓9336ms30132kbC++144.2kb2023-07-05 01:54:262023-07-05 01:54:27

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-05 01:54:27]
  • 评测
  • 测评结果:AC
  • 用时:9336ms
  • 内存:30132kb
  • [2023-07-05 01:54:26]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


constexpr Int INF = 1001001001001001001LL;

int N, M;
vector<int> A, B;
vector<Int> C;

vector<vector<int>> G;
vector<Int> dist;

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d%d", &N, &M);
    A.resize(2 * M);
    B.resize(2 * M);
    C.resize(2 * M);
    for (int i = 0; i < M; ++i) {
      scanf("%d%d%lld", &A[i], &B[i], &C[i]);
      --A[i];
      --B[i];
      A[M + i] = B[i];
      B[M + i] = A[i];
      C[M + i] = C[i];
    }
    M *= 2;
    
    G.assign(N, {});
    for (int i = 0; i < M; ++i) {
      G[A[i]].push_back(i);
    }
    
    using Entry = pair<Int, int>;
    priority_queue<Entry, vector<Entry>, greater<Entry>> que;
    dist.assign(N, INF);
    que.emplace(dist[0] = 0, 0);
    vector<int> us;
    for (; !que.empty(); ) {
      const Int c = que.top().first;
      const int u = que.top().second;
      que.pop();
      if (c == dist[u]) {
        us.push_back(u);
        for (const int i : G[u]) {
          const Int cc = c + C[i];
          const int v = A[i] ^ B[i] ^ u;
          if (chmin(dist[v], cc)) {
            que.emplace(cc, v);
          }
        }
      }
    }
// cerr<<"dist = "<<dist<<endl;
// cerr<<"us = "<<us<<endl;
    assert((int)us.size() == N);
    assert(dist[N - 1] <= 50'000);
    
    vector<int> del(M, 0);
    for (int i = 0; i < M; ++i) {
      if (dist[A[i]] + C[i] != dist[B[i]]) {
        del[i] = 1;
      }
    }
    
    // (max, num)
    vector<pair<Int, int>> dp(N);
    vector<int> prv(N);
    for (Int thr = dist[N - 1] + 1; ; ) {
      fill(dp.begin(), dp.end(), make_pair(-1, 0));
      fill(prv.begin(), prv.end(), -1);
      dp[0] = make_pair(0, 0);
      for (const int u : us) {
        for (const int i : G[u]) if (!del[i]) {
          const Int c = (C[i] < thr) ? C[i] : -1;
          const Int mx = max(dp[u].first, c);
          int num = 0;
          if (mx == dp[u].first) num += dp[u].second;
          if (mx == c) num += 1;
          const int v = B[i];
          if (chmax(dp[v], make_pair(mx, num))) {
            prv[v] = u;
          }
        }
      }
      if (dp[N - 1].second == 0) {
        break;
      }
      for (const int u : us) {
        for (const int i : G[u]) if (!del[i]) {
          const Int c = (C[i] < thr) ? C[i] : -1;
          const Int mx = max(dp[u].first, c);
          int num = 0;
          if (mx == dp[u].first) num += dp[u].second;
          if (mx == c) num += 1;
          const int v = B[i];
          if (dp[v] != make_pair(mx, num)) {
            del[i] = 1;
          }
        }
      }
      thr = dp[N - 1].first;
    }
    
    vector<int> ans;
    for (int u = N - 1; ; ) {
      ans.push_back(u);
      if (u == 0) break;
      u = prv[u];
    }
    reverse(ans.begin(), ans.end());
    printf("%d\n", (int)ans.size());
    for (int h = 0; h < (int)ans.size(); ++h) {
      if (h) printf(" ");
      printf("%d", ans[h] + 1);
    }
    puts("");
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3640kb

input:

2
4 6
1 2 1
1 3 2
2 3 1
2 4 2
3 4 1
1 4 4
6 11
1 2 9
2 3 12
3 4 3
4 5 5
5 6 10
6 1 22
2 4 9
3 6 1
4 6 5
2 5 2
3 5 8

output:

3
1 2 4
5
1 2 5 3 6

result:

ok correct (2 test cases)

Test #2:

score: 0
Accepted
time: 438ms
memory: 3892kb

input:

600
320 1547
204 81 13768
232 97 9939
97 249 3719
201 109 14322
183 132 40881
142 143 1
275 186 24548
18 236 7907
30 317 11845
131 130 1
311 300 11704
141 92 41925
174 191 32128
119 120 1
184 183 1
310 309 1
283 270 25477
233 141 36076
212 92 13770
307 110 40656
218 137 14033
180 85 41892
200 199 44...

output:

184
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...

result:

ok correct (600 test cases)

Test #3:

score: 0
Accepted
time: 534ms
memory: 30132kb

input:

4
100000 220000
48940 43355 42347
77914 77913 1
45236 82683 42904
22563 16038 34866
81537 81538 43088
49803 51485 25497
63071 25523 14336
44102 39850 43782
13607 92386 16724
98711 73651 46840
17775 16801 28765
5757 98829 13508
85095 48444 1
9198 43003 32678
14461 14462 1
20245 48742 18138
89120 8911...

output:

35000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...

result:

ok correct (4 test cases)

Test #4:

score: 0
Accepted
time: 9336ms
memory: 28376kb

input:

4
100000 160000
5533 94547 28459
14992 20984 20548
70133 92512 27510
9013 9012 304
13621 40571 47787
305 306 262
6987 6988 135
16234 16992 40656
26246 49196 27701
19103 60272 44055
91532 91531 38290
70778 68341 35147
32524 32523 13
85786 50300 40970
49277 29735 13942
43446 34519 42455
77623 17031 34...

output:

316
1 2 3 4 5 6 97410 97409 26434 26435 26436 26437 98883 1370 1369 1368 92157 92158 4815 4816 4817 4818 50181 16985 89607 89608 24674 16979 16980 38428 13232 13233 13234 13664 13663 95009 7166 7165 7164 7163 24798 24799 11787 31031 53551 7309 7310 35482 7933 25067 32714 32715 44194 2068 72216 79593...

result:

ok correct (4 test cases)

Test #5:

score: 0
Accepted
time: 527ms
memory: 27456kb

input:

4
100000 160000
89517 25671 43802
21059 21058 1
35299 91834 43615
53383 53382 1
27213 39161 17202
10715 4050 30342
44100 44099 1
24162 28648 7378
19022 23084 37734
66056 97934 14651
31566 89391 23215
91038 91037 1
47695 47696 6099
99142 99143 1
83908 73654 15060
15551 22001 8896
55190 55189 1
26536 ...

output:

632
1 94652 1699 1698 1697 31170 31169 31168 31279 38643 38642 38641 38640 38639 38638 38637 38636 38635 38634 38633 38632 38631 38630 38629 38628 38627 38626 38625 38624 38623 38622 38621 38620 38619 38618 38617 38616 38615 38614 38613 38612 38611 38610 38609 38608 38607 38606 38605 38604 38603 386...

result:

ok correct (4 test cases)