QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#446497#7737. Extending DistanceZSH_ZSHWA 6ms3956kbC++148.7kb2024-06-17 11:44:332024-06-17 11:44:33

Judging History

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

  • [2024-06-17 11:44:33]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3956kb
  • [2024-06-17 11:44:33]
  • 提交

answer

#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;

template <typename T> class flow_graph {
public:
  static constexpr T eps = (T)1e-9;

  struct edge {
    int to;
    T c;
    T f;
    int rev;
  };

  vector<vector<edge>> g;
  vector<int> ptr;
  vector<int> d;
  vector<int> q;
  int n;
  int st, fin;
  T flow;

  flow_graph(int _n, int _st, int _fin) : n(_n), st(_st), fin(_fin) {
    assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin);
    g.resize(n);
    ptr.resize(n);
    d.resize(n);
    q.resize(n);
    flow = 0;
  }

  void clear_flow() {
    for (int i = 0; i < n; i++) {
      for (edge &e : g[i]) {
        e.f = 0;
      }
    }
    flow = 0;
  }

  void add(int from, int to, T forward_cap, T backward_cap) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    int from_size = g[from].size();
    int to_size = g[to].size();
    g[from].push_back({to, forward_cap, 0, to_size});
    g[to].push_back({from, backward_cap, 0, from_size});
  }

  bool expath() {
    fill(d.begin(), d.end(), -1);
    q[0] = fin;
    d[fin] = 0;
    int beg = 0, end = 1;
    while (beg < end) {
      int i = q[beg++];
      for (const edge &e : g[i]) {
        const edge &back = g[e.to][e.rev];
        if (back.c - back.f > eps && d[e.to] == -1) {
          d[e.to] = d[i] + 1;
          if (e.to == st) {
            return true;
          }
          q[end++] = e.to;
        }
      }
    }
    return false;
  }

  T dfs(int v, T w) {
    if (v == fin) {
      return w;
    }
    int &j = ptr[v];
    while (j >= 0) {
      const edge &e = g[v][j];
      if (e.c - e.f > eps && d[e.to] == d[v] - 1) {
        T t = dfs(e.to, min(e.c - e.f, w));
        if (t > eps) {
          g[v][j].f += t;
          g[e.to][e.rev].f -= t;
          return t;
        }
      }
      j--;
    }
    return 0;
  }

  T max_flow() {
    while (expath()) {
      for (int i = 0; i < n; i++) {
        ptr[i] = (int)g[i].size() - 1;
      }
      T big_add = 0;
      while (true) {
        T add = dfs(st, numeric_limits<T>::max());
        if (add <= eps) {
          break;
        }
        big_add += add;
      }
      if (big_add <= eps) {
        break;
      }
      flow += big_add;
    }
    return flow;
  }

  vector<bool> min_cut() {
    max_flow();
    vector<bool> ret(n);
    for (int i = 0; i < n; i++) {
      ret[i] = (d[i] != -1);
    }
    return ret;
  }
};

template <typename T, typename C> class mcmf {
public:
  static constexpr T eps = (T)1e-9;

  struct edge {
    int from;
    int to;
    T c;
    T f;
    C cost;
  };

  vector<vector<int>> g;
  vector<edge> edges;
  vector<C> d;
  vector<int> q;
  vector<bool> in_queue;
  vector<int> pe;
  int n;
  int st, fin;
  T flow;
  C cost;

  mcmf(int _n, int _st, int _fin) : n(_n), st(_st), fin(_fin) {
    assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin);
    g.resize(n);
    d.resize(n);
    in_queue.resize(n);
    pe.resize(n);
    flow = 0;
    cost = 0;
  }

  void clear_flow() {
    for (const edge &e : edges) {
      e.f = 0;
    }
    flow = 0;
  }

  void add_edge(int from, int to, T cap, T flow) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    g[from].push_back((int)edges.size());
    edges.push_back({from, to, cap, flow, 0});
    g[to].push_back((int)edges.size());
    edges.push_back({to, from, cap, -flow, 0});
  }

  void add(int from, int to, T forward_cap, T backward_cap, C cost) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    g[from].push_back((int)edges.size());
    edges.push_back({from, to, forward_cap, 0, cost});
    g[to].push_back((int)edges.size());
    edges.push_back({to, from, backward_cap, 0, -cost});
  }

  bool expath() {
    fill(d.begin(), d.end(), numeric_limits<C>::max());
    q.clear();
    q.push_back(st);
    d[st] = 0;
    in_queue[st] = true;
    int beg = 0;
    bool found = false;
    while (beg < (int)q.size()) {
      int i = q[beg++];
      if (i == fin) {
        found = true;
      }
      in_queue[i] = false;
      for (int id : g[i]) {
        const edge &e = edges[id];
        if (e.c - e.f > eps && d[i] + e.cost < d[e.to]) {
          d[e.to] = d[i] + e.cost;
          pe[e.to] = id;
          if (!in_queue[e.to]) {
            q.push_back(e.to);
            in_queue[e.to] = true;
          }
        }
      }
    }
    if (found) {
      T push = 1;
      int v = fin;
      while (v != st) {
        const edge &e = edges[pe[v]];
        push = min(push, e.c - e.f);
        v = e.from;
      }
      v = fin;
      while (v != st) {
        edge &e = edges[pe[v]];
        e.f += push;
        edge &back = edges[pe[v] ^ 1];
        back.f -= push;
        v = e.from;
      }
      flow += push;
      cost += push * d[fin];
    }
    return found;
  }

  pair<T, C> max_flow_min_cost() {
    while (expath()) {
    }
    return make_pair(flow, cost);
  }
  pair<T, C> k_iters(int k) {
    for (int i = 0; i < k; ++i) {
      assert(expath());
    }
    return make_pair(flow, cost);
  }
};

/*
2
3 4 6
2 1 15
7 1 9
13 3 2
3 6 1 2
5 2 15 3
3 3 3
1 1
2 2
3 3
1 1 1
2 2 2
*/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<vector<int>>> ed(n, vector<vector<int>>(m, vector<int>(2)));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m - 1; ++j) {
        cin >> ed[i][j][1];
      }
    }
    for (int i = 0; i < n - 1; ++i) {
      for (int j = 0; j < m; ++j) {
        cin >> ed[i][j][0];
      }
    }
    int nrows = n - 1, ncols = m - 1;
    int s = nrows * ncols, t = s + 1;
    int num_ver = t + 1;
    flow_graph<int> g(num_ver, s, t);
    for (int i = 0; i < m - 1; ++i) {
      g.add(s, i, ed[0][i][1], ed[0][i][1]);
      g.add((nrows - 1) * ncols + i, t, ed[nrows][i][1], ed[nrows][i][1]);
    }
    for (int i = 0; i < nrows; ++i) {
      for (int j = 0; j < ncols; ++j) {
        if (i + 1 < nrows) {
          g.add(i * ncols + j, (i + 1) * ncols + j, ed[i + 1][j][1],
                ed[i + 1][j][1]);
        }
        if (j + 1 < ncols) {
          g.add(i * ncols + j, i * ncols + (j + 1), ed[i][j + 1][0],
                ed[i][j + 1][0]);
        }
      }
    }
    g.max_flow();
    mcmf<int, int> cg(num_ver, s, t);
    for (int i = 0; i < num_ver; ++i) {
      for (auto edge : g.g[i]) {
        if (i < edge.to) {
          cg.add_edge(i, edge.to, edge.c, edge.f);
        }
      }
    }
    for (int i = 0; i < m - 1; ++i) {
      cg.add(s, i, k, 0, 1);
      cg.add((nrows - 1) * ncols + i, t, k, 0, 1);
    }
    for (int i = 0; i < nrows; ++i) {
      for (int j = 0; j < ncols; ++j) {
        if (i + 1 < nrows) {
          cg.add(i * ncols + j, (i + 1) * ncols + j, k, 0, 1);
          cg.add((i + 1) * ncols + j, i * ncols + j, k, 0, 1);
        }
        if (j + 1 < ncols) {
          cg.add(i * ncols + j, i * ncols + (j + 1), k, 0, 1);
          cg.add(i * ncols + (j + 1), i * ncols + j, k, 0, 1);
        }
      }
    }
    int ans = cg.k_iters(k).second;
    cout << ans << '\n';
    vector<vector<vector<int>>> ned = ed;
    for (auto edge : cg.edges) {
      if (edge.cost == 1 && edge.f > 0) {
        int u = edge.from, v = edge.to;
        if (u == s) {
          ned[0][v][1] += edge.f;
        } else if (v == t) {
          ned[nrows][u % ncols][1] += edge.f;
        } else {
          int iu = u / ncols, ju = u % ncols;
          int iv = v / ncols, jv = v % ncols;
          if (make_pair(iu, ju) > make_pair(iv, jv)) {
            swap(iu, iv);
            swap(ju, jv);
          }
          if (iu + 1 == iv) {
            assert(ju == jv);
            ned[iu + 1][ju][1] += edge.f;
          } else if (ju + 1 == jv) {
            assert(iu == iv);
            ned[iu][ju + 1][0] += edge.f;
          } else {
            assert(false);
          }
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m - 1; ++j) {
        cout << ned[i][j][1] << ' ';
      }
      cout << '\n';
    }
    for (int i = 0; i < n - 1; ++i) {
      for (int j = 0; j < m; ++j) {
        cout << ned[i][j][0] << ' ';
      }
      cout << '\n';
    }
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3636kb

input:

2
3 4 6
2 1 15
7 1 9
13 3 2
3 6 1 2
5 2 15 3
3 3 3
1 1
2 2
3 3
1 1 1
2 2 2

output:

9
4 1 15 
7 1 12 
13 3 6 
3 6 1 2 
5 2 15 3 
4
3 2 
3 2 
3 3 
1 1 1 
2 2 2 

result:

ok Correct. (2 test cases)

Test #2:

score: 0
Accepted
time: 3ms
memory: 3652kb

input:

125
4 4 48
33 9 39
38 74 3
18 44 9
20 91 19
76 95 17 16
61 88 50 49
68 18 33 84
4 4 14
54 69 42
47 90 28
2 73 59
1 20 90
43 22 74 19
27 67 46 43
42 21 78 80
4 4 93
12 67 38
13 85 39
74 68 77
71 80 64
92 97 53 46
66 6 30 20
66 70 71 24
4 4 34
43 86 55
49 34 73
78 77 90
99 49 5
55 4 63 47
80 24 15 3
8...

output:

87
35 39 39 
38 74 19 
20 71 19 
20 91 19 
76 95 17 16 
61 88 50 49 
68 18 33 84 
14
54 69 42 
47 90 28 
2 73 59 
2 33 90 
43 22 74 19 
27 67 46 43 
42 21 78 80 
166
74 85 51 
74 85 51 
74 68 77 
71 80 64 
92 97 53 46 
66 6 30 20 
66 70 71 24 
34
45 86 55 
49 37 73 
78 77 90 
99 49 34 
55 4 63 47 
8...

result:

ok Correct. (125 test cases)

Test #3:

score: 0
Accepted
time: 3ms
memory: 3656kb

input:

80
5 5 97
10 18 14 13
17 15 16 11
15 10 14 15
12 17 12 15
12 11 15 15
19 19 13 19 19
19 17 10 10 19
12 13 18 11 20
12 17 14 13 12
5 5 65
13 15 13 20
18 19 13 20
10 19 18 17
19 19 11 14
12 18 11 10
18 14 18 19 18
20 11 17 11 17
16 13 19 18 13
16 14 17 11 18
5 5 3
15 10 10 18
17 17 17 14
13 15 15 19
1...

output:

473
105 18 14 13 
108 15 16 11 
109 12 14 15 
106 17 12 15 
106 14 15 15 
19 19 13 19 19 
19 17 10 10 19 
12 13 18 11 20 
12 17 14 13 12 
271
67 15 13 21 
64 19 13 20 
62 19 18 17 
71 19 11 15 
72 18 11 15 
18 14 18 19 18 
20 11 17 11 17 
16 13 19 18 13 
16 14 17 11 18 
3
18 10 10 18 
17 17 17 14 
1...

result:

ok Correct. (80 test cases)

Test #4:

score: 0
Accepted
time: 4ms
memory: 3884kb

input:

55
6 6 98
943830625 154853276 396311720 585129723 216006508
789713291 522861691 174874210 616414184 931597164
831871942 149821142 520941619 814161584 200419736
646044877 574761262 188910317 673355715 723256093
264106685 163628126 318085983 226850181 101764170
179381345 486537031 346100002 805792579 ...

output:

98
943830625 154853276 396311720 585129723 216006508 
789713291 522861691 174874210 616414184 931597164 
831871942 149821142 520941619 814161584 200419736 
646044877 574761262 188910317 673355715 723256093 
264106685 163628224 318085983 226850181 101764170 
179381345 486537031 346100002 805792579 50...

result:

ok Correct. (55 test cases)

Test #5:

score: 0
Accepted
time: 4ms
memory: 3664kb

input:

55
6 6 96
16739843 17336211 10384494 17185421 10646458
18552039 13790956 13642043 10307995 14193711
19297204 12810329 18681558 18724838 16636750
11505737 19658923 19307194 12241535 15070027
16123862 17524159 19471242 14316479 10954501
10604286 17691735 17352365 14092770 19909253
11761060 19372581 16...

output:

96
16739843 17336211 10384494 17185421 10646458 
18552039 13790956 13642043 10308091 14193711 
19297204 12810329 18681558 18724838 16636750 
11505737 19658923 19307194 12241535 15070027 
16123862 17524159 19471242 14316479 10954501 
10604286 17691735 17352365 14092770 19909253 
11761060 19372581 168...

result:

ok Correct. (55 test cases)

Test #6:

score: 0
Accepted
time: 2ms
memory: 3604kb

input:

40
7 7 17
27500 8466 7754 5254 45204 36821
35457 23725 45494 26962 24728 31437
46232 38720 23756 17265 21004 25959
29727 6060 23244 45236 39610 23968
17068 14954 9745 28949 20957 30885
8272 49710 28660 17038 12058 48058
10306 5065 45011 25264 25765 17423
21072 22743 17503 11324 10214 6879 22253
1729...

output:

17
27500 8466 7771 5254 45204 36821 
35457 23725 45494 26962 24728 31437 
46232 38720 23756 17265 21004 25959 
29727 6060 23244 45236 39610 23968 
17068 14954 9745 28949 20957 30885 
8272 49710 28660 17038 12058 48058 
10306 5065 45011 25264 25765 17423 
21072 22743 17503 11324 10214 6879 22253 
172...

result:

ok Correct. (40 test cases)

Test #7:

score: 0
Accepted
time: 4ms
memory: 3688kb

input:

31
8 8 84
82373 175391 615535 844446 885043 54908 235817
174599 782716 140021 505505 551220 980613 844864
490309 720051 436451 436322 357173 349094 303200
428983 865478 890817 50236 172208 96832 261006
265321 413840 490656 677420 172238 872751 182871
957260 978182 971447 603592 37811 282590 470570
1...

output:

84
82373 175391 615535 844446 885043 54908 235817 
174599 782716 140021 505505 551220 980613 844864 
490309 720051 436451 436322 357173 349094 303200 
428983 865478 890817 50236 172208 96916 261006 
265321 413840 490656 677420 172238 872751 182871 
957260 978182 971447 603592 37811 282590 470570 
13...

result:

ok Correct. (31 test cases)

Test #8:

score: 0
Accepted
time: 5ms
memory: 3628kb

input:

24
9 9 80
178 146 100 118 196 180 100 110
153 125 200 139 174 169 163 196
173 167 120 182 172 142 188 132
160 150 148 171 162 125 180 152
159 152 161 177 106 129 152 114
179 132 146 126 107 148 141 151
165 123 151 153 112 151 148 182
105 188 136 199 173 192 117 118
116 190 103 198 125 150 105 118
15...

output:

227
178 146 122 118 196 186 111 128 
153 125 200 139 174 169 163 196 
173 167 120 182 172 142 188 132 
160 150 148 171 162 125 180 152 
159 152 161 177 106 129 152 149 
179 132 155 126 107 148 141 197 
165 123 151 153 112 151 148 182 
105 188 136 199 173 192 117 118 
116 190 112 198 184 162 105 118 ...

result:

ok Correct. (24 test cases)

Test #9:

score: 0
Accepted
time: 4ms
memory: 3708kb

input:

20
10 10 91
90000001 90000000 90000001 90000000 90000001 90000000 90000000 90000001 90000000
90000001 90000001 90000001 90000001 90000000 90000001 90000001 90000001 90000001
90000001 90000001 90000001 90000000 90000000 90000000 90000001 90000000 90000000
90000000 90000001 90000001 90000001 90000000 ...

output:

886
90000087 90000000 90000001 90000001 90000001 90000001 90000001 90000001 90000001 
90000087 90000001 90000001 90000001 90000000 90000001 90000001 90000001 90000001 
90000087 90000001 90000001 90000001 90000000 90000001 90000002 90000000 90000001 
90000086 90000001 90000001 90000002 90000000 90000...

result:

ok Correct. (20 test cases)

Test #10:

score: 0
Accepted
time: 6ms
memory: 3648kb

input:

10
14 14 68
20 23 20 22 23 26 23 22 28 30 25 20 29
22 30 26 20 22 21 26 23 23 22 22 22 21
24 29 30 30 24 20 25 23 30 27 27 26 24
30 25 25 24 26 26 23 22 22 30 24 20 23
27 24 29 24 22 24 21 20 20 28 24 21 28
20 24 25 29 20 30 30 30 30 24 27 23 28
29 25 25 26 21 27 23 25 25 27 23 27 23
23 22 27 27 29 ...

output:

607
48 23 24 28 24 26 24 24 34 30 28 25 30 
52 32 31 26 23 21 27 27 31 22 26 27 23 
52 29 30 30 24 20 25 24 30 27 27 26 24 
58 25 25 24 26 26 31 27 24 30 26 20 26 
55 24 29 24 22 24 30 26 25 28 28 21 32 
48 24 25 29 20 30 30 30 30 24 27 23 28 
57 25 25 26 22 27 28 26 26 29 24 27 26 
51 22 27 27 29 3...

result:

ok Correct. (10 test cases)

Test #11:

score: 0
Accepted
time: 2ms
memory: 3956kb

input:

10
10 20 79
1001 1003 1000 1003 1001 1003 1002 1003 1001 1003 1003 1000 1001 1001 1001 1002 1002 1003 1002
1001 1003 1001 1001 1001 1000 1003 1002 1000 1002 1001 1001 1003 1000 1001 1003 1001 1001 1000
1001 1003 1000 1002 1003 1003 1003 1001 1002 1002 1000 1002 1003 1001 1003 1000 1002 1000 1002
100...

output:

732
1069 1003 1000 1003 1001 1003 1002 1003 1001 1003 1003 1000 1001 1001 1001 1002 1002 1003 1002 
1070 1003 1001 1001 1003 1003 1003 1002 1002 1003 1001 1001 1003 1000 1001 1003 1001 1001 1001 
1070 1003 1000 1002 1003 1003 1003 1001 1002 1003 1000 1002 1003 1001 1003 1000 1002 1000 1002 
1071 100...

result:

ok Correct. (10 test cases)

Test #12:

score: 0
Accepted
time: 6ms
memory: 3764kb

input:

10
20 10 21
777601561 917773453 313011120 861769383 651010533 771534309 418153755 749795307 939533489
769621271 705696594 863041783 330858635 136276987 569175453 21935211 559486868 264609946
30013079 725693020 492377730 630078388 365743281 693415122 589281054 690370363 47310510
125777481 136448711 5...

output:

21
777601561 917773453 313011120 861769383 651010533 771534309 418153755 749795307 939533489 
769621271 705696594 863041783 330858635 136276987 569175453 21935211 559486868 264609946 
30013079 725693020 492377730 630078388 365743281 693415122 589281054 690370363 47310510 
125777481 136448711 5089256...

result:

ok Correct. (10 test cases)

Test #13:

score: 0
Accepted
time: 3ms
memory: 3680kb

input:

24
6 2 37
1
1
1
1
1
1
1 1
1 1
1 1
1 1
1 1
9 18 13
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 ...

output:

222
38 
38 
38 
38 
38 
38 
1 1 
1 1 
1 1 
1 1 
1 1 
117
14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
14 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok Correct. (24 test cases)

Test #14:

score: 0
Accepted
time: 4ms
memory: 3792kb

input:

31
9 3 33
1 5
4 5
3 4
4 2
5 3
4 3
2 5
5 5
4 3
5 1 4
2 1 2
1 5 3
5 3 2
2 3 2
3 5 3
4 4 3
1 4 2
2 3 4
3 2
5 2
1 3 5
12 6 72
2 2 1 1 5
1 2 5 1 4
5 5 1 2 3
4 1 4 4 4
1 2 2 2 5
5 5 3 5 3
2 1 1 3 5
4 1 4 2 1
4 2 1 5 3
3 3 2 4 5
5 5 2 3 3
4 3 4 5 1
3 5 5 5 1 1
5 5 3 2 5 3
5 3 1 4 3 3
5 4 5 1 3 5
2 3 3 5 4 ...

output:

284
33 6 
33 6 
34 5 
36 3 
35 4 
35 4 
33 6 
34 5 
35 4 
5 1 4 
2 1 2 
1 5 3 
5 3 2 
2 3 2 
3 5 3 
4 4 3 
1 4 2 
6
7 2 
7 2 
1 3 5 
803
65 4 5 2 6 
64 4 7 2 5 
66 5 4 3 4 
66 4 4 4 4 
64 6 3 3 6 
65 5 3 5 4 
66 4 1 6 5 
66 4 4 3 5 
66 5 1 5 5 
65 6 2 4 5 
66 6 2 4 4 
66 5 4 5 2 
3 5 5 5 1 1 
5 5 3 ...

result:

ok Correct. (31 test cases)

Test #15:

score: -100
Wrong Answer
time: 4ms
memory: 3800kb

input:

27
14 3 50
998244355 998244354
998244353 998244355
998244355 998244354
998244353 998244353
998244353 998244354
998244353 998244354
998244355 998244353
998244354 998244354
998244355 998244354
998244354 998244354
998244355 998244355
998244354 998244355
998244354 998244355
998244354 998244353
998244354...

output:

670
998244402 998244354 
998244401 998244355 
998244402 998244354 
998244402 998244354 
998244402 998244354 
998244402 998244354 
998244403 998244353 
998244402 998244354 
998244402 998244354 
998244401 998244355 
998244401 998244355 
998244401 998244355 
998244401 998244355 
998244401 998244355 
99...

result:

wrong answer The length of shortest path shoult extend exactly K. (test case 8)