Submission #951540

# Submission time Handle Problem Language Result Execution time Memory
951540 2024-03-22T05:31:26 Z qwe1rt1yuiop1 Reconstruction Project (JOI22_reconstruction) C++17
7 / 100
5000 ms 5208 KB
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;


vector<int> dsu, sz;
int f(int x) { return x == dsu[x] ? x : dsu[x] = f(dsu[x]); }
void un(int a, int b)
{
    a = f(a), b = f(b);
    if (a == b)
        return;
    if (sz[a] < sz[b])
        swap(a, b);
    dsu[b] = a, sz[a] += sz[b];
}

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<array<int, 3>> e0(m);
    for (auto &i : e0)
        cin >> i[1] >> i[2] >> i[0], --i[1], --i[2];
    
    int q;
    cin >> q;
    while (q--)
    {
        int x;
        cin >> x;
        auto e = e0;
        for (auto &[w, a, b] : e)
            w = abs(w - x);
        sort(all(e));
        sz.assign(n, 1), dsu = sz;
        for (int i = 0; i < n; ++i)
            dsu[i] = i;
        int ans = 0;
        for (auto [w, a, b] : e)
            if (f(a) != f(b))
            {
                un(a, b);
                ans += w;
            }
        cout << ans << '\n';
    }
}

/*
5 10
1 2 8
1 3 13
1 4 5
1 5 11
1 5 3
2 3 7
2 4 15
3 4 6
3 5 6
4 5 2
6
3
6
8
10
13
17
*/

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 112 ms 5208 KB Output is correct
21 Correct 111 ms 5140 KB Output is correct
22 Correct 131 ms 4948 KB Output is correct
23 Correct 109 ms 5116 KB Output is correct
24 Correct 110 ms 4952 KB Output is correct
25 Correct 114 ms 4964 KB Output is correct
26 Correct 112 ms 4956 KB Output is correct
27 Correct 110 ms 5136 KB Output is correct
28 Correct 133 ms 5116 KB Output is correct
29 Correct 158 ms 5120 KB Output is correct
30 Correct 107 ms 4956 KB Output is correct
31 Correct 110 ms 4956 KB Output is correct
32 Correct 109 ms 4952 KB Output is correct
33 Correct 122 ms 4948 KB Output is correct
34 Correct 152 ms 5120 KB Output is correct
35 Correct 109 ms 5168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Execution timed out 5028 ms 5160 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Execution timed out 5069 ms 1948 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 112 ms 5208 KB Output is correct
21 Correct 111 ms 5140 KB Output is correct
22 Correct 131 ms 4948 KB Output is correct
23 Correct 109 ms 5116 KB Output is correct
24 Correct 110 ms 4952 KB Output is correct
25 Correct 114 ms 4964 KB Output is correct
26 Correct 112 ms 4956 KB Output is correct
27 Correct 110 ms 5136 KB Output is correct
28 Correct 133 ms 5116 KB Output is correct
29 Correct 158 ms 5120 KB Output is correct
30 Correct 107 ms 4956 KB Output is correct
31 Correct 110 ms 4956 KB Output is correct
32 Correct 109 ms 4952 KB Output is correct
33 Correct 122 ms 4948 KB Output is correct
34 Correct 152 ms 5120 KB Output is correct
35 Correct 109 ms 5168 KB Output is correct
36 Execution timed out 5067 ms 5148 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 112 ms 5208 KB Output is correct
21 Correct 111 ms 5140 KB Output is correct
22 Correct 131 ms 4948 KB Output is correct
23 Correct 109 ms 5116 KB Output is correct
24 Correct 110 ms 4952 KB Output is correct
25 Correct 114 ms 4964 KB Output is correct
26 Correct 112 ms 4956 KB Output is correct
27 Correct 110 ms 5136 KB Output is correct
28 Correct 133 ms 5116 KB Output is correct
29 Correct 158 ms 5120 KB Output is correct
30 Correct 107 ms 4956 KB Output is correct
31 Correct 110 ms 4956 KB Output is correct
32 Correct 109 ms 4952 KB Output is correct
33 Correct 122 ms 4948 KB Output is correct
34 Correct 152 ms 5120 KB Output is correct
35 Correct 109 ms 5168 KB Output is correct
36 Correct 0 ms 600 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Execution timed out 5028 ms 5160 KB Time limit exceeded
40 Halted 0 ms 0 KB -