답안 #1061209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1061209 2024-08-16T07:15:42 Z kunzaZa183 Reconstruction Project (JOI22_reconstruction) C++17
3 / 100
5000 ms 6740 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int n, m;
  cin >> n >> m;

  const int maxm = 1e5, maxn = 500;

  struct edge {
    int a, b, we;
  };
  vector<edge> elist(maxm);

  for (int i = 0; i < m; i++)
    cin >> elist[i].a >> elist[i].b >> elist[i].we;

  int qs;
  cin >> qs;
  while (qs--) {
    vector<int> dsu(maxn);
    iota(dsu.begin(), dsu.end(), 0);

    int x;
    cin >> x;
    vector<edge> ve(elist);
    for (int i = 0; i < m; i++) {
      ve[i].we = abs(ve[i].we - x);
    }

    sort(ve.begin(), ve.end(), [&](edge a, edge b) { return a.we < b.we; });

    function<int(int)> par = [&](int cur) {
      if (dsu[cur] == cur)
        return cur;
      dsu[cur] = par(dsu[cur]);
      return dsu[cur];
    };

    int cost = 0;
    for (auto a : ve) {
      if (par(a.a) != par(a.b)) {
        cost += a.we;
        dsu[par(a.a)] = par(a.b);
      }
    }

    cout << cost << "\n";
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 4956 KB Output is correct
2 Correct 10 ms 4956 KB Output is correct
3 Correct 22 ms 4956 KB Output is correct
4 Correct 22 ms 4952 KB Output is correct
5 Correct 22 ms 4956 KB Output is correct
6 Correct 22 ms 4956 KB Output is correct
7 Correct 22 ms 4952 KB Output is correct
8 Correct 22 ms 5116 KB Output is correct
9 Correct 22 ms 4956 KB Output is correct
10 Correct 21 ms 5172 KB Output is correct
11 Correct 24 ms 4956 KB Output is correct
12 Correct 4 ms 4956 KB Output is correct
13 Correct 21 ms 5148 KB Output is correct
14 Correct 23 ms 4956 KB Output is correct
15 Correct 22 ms 5172 KB Output is correct
16 Correct 22 ms 4956 KB Output is correct
17 Correct 23 ms 4956 KB Output is correct
18 Correct 22 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 4956 KB Output is correct
2 Correct 10 ms 4956 KB Output is correct
3 Correct 22 ms 4956 KB Output is correct
4 Correct 22 ms 4952 KB Output is correct
5 Correct 22 ms 4956 KB Output is correct
6 Correct 22 ms 4956 KB Output is correct
7 Correct 22 ms 4952 KB Output is correct
8 Correct 22 ms 5116 KB Output is correct
9 Correct 22 ms 4956 KB Output is correct
10 Correct 21 ms 5172 KB Output is correct
11 Correct 24 ms 4956 KB Output is correct
12 Correct 4 ms 4956 KB Output is correct
13 Correct 21 ms 5148 KB Output is correct
14 Correct 23 ms 4956 KB Output is correct
15 Correct 22 ms 5172 KB Output is correct
16 Correct 22 ms 4956 KB Output is correct
17 Correct 23 ms 4956 KB Output is correct
18 Correct 22 ms 4956 KB Output is correct
19 Correct 22 ms 4952 KB Output is correct
20 Incorrect 125 ms 6740 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 4952 KB Output is correct
2 Correct 4 ms 4952 KB Output is correct
3 Correct 23 ms 4956 KB Output is correct
4 Execution timed out 5023 ms 5140 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 4956 KB Output is correct
2 Correct 10 ms 4956 KB Output is correct
3 Correct 22 ms 4956 KB Output is correct
4 Correct 22 ms 4952 KB Output is correct
5 Correct 22 ms 4956 KB Output is correct
6 Correct 22 ms 4956 KB Output is correct
7 Correct 22 ms 4952 KB Output is correct
8 Correct 22 ms 5116 KB Output is correct
9 Correct 22 ms 4956 KB Output is correct
10 Correct 21 ms 5172 KB Output is correct
11 Correct 24 ms 4956 KB Output is correct
12 Correct 4 ms 4956 KB Output is correct
13 Correct 21 ms 5148 KB Output is correct
14 Correct 23 ms 4956 KB Output is correct
15 Correct 22 ms 5172 KB Output is correct
16 Correct 22 ms 4956 KB Output is correct
17 Correct 23 ms 4956 KB Output is correct
18 Correct 22 ms 4956 KB Output is correct
19 Correct 21 ms 4952 KB Output is correct
20 Execution timed out 5059 ms 5500 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 4956 KB Output is correct
2 Correct 10 ms 4956 KB Output is correct
3 Correct 22 ms 4956 KB Output is correct
4 Correct 22 ms 4952 KB Output is correct
5 Correct 22 ms 4956 KB Output is correct
6 Correct 22 ms 4956 KB Output is correct
7 Correct 22 ms 4952 KB Output is correct
8 Correct 22 ms 5116 KB Output is correct
9 Correct 22 ms 4956 KB Output is correct
10 Correct 21 ms 5172 KB Output is correct
11 Correct 24 ms 4956 KB Output is correct
12 Correct 4 ms 4956 KB Output is correct
13 Correct 21 ms 5148 KB Output is correct
14 Correct 23 ms 4956 KB Output is correct
15 Correct 22 ms 5172 KB Output is correct
16 Correct 22 ms 4956 KB Output is correct
17 Correct 23 ms 4956 KB Output is correct
18 Correct 22 ms 4956 KB Output is correct
19 Correct 22 ms 4952 KB Output is correct
20 Incorrect 125 ms 6740 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 4956 KB Output is correct
2 Correct 10 ms 4956 KB Output is correct
3 Correct 22 ms 4956 KB Output is correct
4 Correct 22 ms 4952 KB Output is correct
5 Correct 22 ms 4956 KB Output is correct
6 Correct 22 ms 4956 KB Output is correct
7 Correct 22 ms 4952 KB Output is correct
8 Correct 22 ms 5116 KB Output is correct
9 Correct 22 ms 4956 KB Output is correct
10 Correct 21 ms 5172 KB Output is correct
11 Correct 24 ms 4956 KB Output is correct
12 Correct 4 ms 4956 KB Output is correct
13 Correct 21 ms 5148 KB Output is correct
14 Correct 23 ms 4956 KB Output is correct
15 Correct 22 ms 5172 KB Output is correct
16 Correct 22 ms 4956 KB Output is correct
17 Correct 23 ms 4956 KB Output is correct
18 Correct 22 ms 4956 KB Output is correct
19 Correct 22 ms 4952 KB Output is correct
20 Incorrect 125 ms 6740 KB Output isn't correct
21 Halted 0 ms 0 KB -