답안 #881265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881265 2023-12-01T02:49:30 Z Regulus Reconstruction Project (JOI22_reconstruction) C++17
7 / 100
5000 ms 8900 KB
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define debug(x) cerr << #x << " = " << (x) << ' '
#define endl cerr << '\n'
#define all(v) (v).begin(), (v).end()
#define SZ(v) (ll)(v).size()
#define lowbit(x) (x)&-(x)
#define pb emplace_back
#define F first
#define S second
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using ppl = pair<pll, ll>;
using plp = pair<ll, pll>;

const int N = 505;
const int MxE = 1e5+5;
ll x[MxE], y[MxE], w[MxE], dsu[N];
vector<plp> v;

inline int query(int x) { return (dsu[x]<0)?x : dsu[x]=query(dsu[x]); }

int main(void)
{ IO
    ll n, i, m, Q, ans, j, want;

    cin >> n >> m;
    for (i=1; i <= m; ++i)
        cin >> x[i] >> y[i] >> w[i];
    cin >> Q;
    for (i=1; i <= Q; ++i)
    {
        cin >> want;
        for (j=1; j <= n; ++j) dsu[j] = -1;
        v.clear();
        for (j=1; j <= m; ++j)
            v.pb(abs(want-w[j]), pll{x[j], y[j]});
        sort(all(v));
        ans = 0;
        for (auto e : v)
        {
            int x = e.S.F, y = e.S.S;
            if (query(x) != query(y))
                ans += e.F, dsu[query(x)] = query(y);
        }
        cout << ans << '\n';
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2512 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2552 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2620 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2512 KB Output is correct
15 Correct 0 ms 2508 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2512 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2552 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2620 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2512 KB Output is correct
15 Correct 0 ms 2508 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 94 ms 8772 KB Output is correct
21 Correct 100 ms 7624 KB Output is correct
22 Correct 96 ms 7624 KB Output is correct
23 Correct 96 ms 8448 KB Output is correct
24 Correct 96 ms 7624 KB Output is correct
25 Correct 98 ms 7632 KB Output is correct
26 Correct 94 ms 8320 KB Output is correct
27 Correct 99 ms 7660 KB Output is correct
28 Correct 116 ms 7632 KB Output is correct
29 Correct 133 ms 7632 KB Output is correct
30 Correct 96 ms 7860 KB Output is correct
31 Correct 95 ms 8900 KB Output is correct
32 Correct 96 ms 7620 KB Output is correct
33 Correct 95 ms 7620 KB Output is correct
34 Correct 120 ms 7632 KB Output is correct
35 Correct 96 ms 8168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2512 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Execution timed out 5058 ms 7776 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2512 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2552 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2620 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2512 KB Output is correct
15 Correct 0 ms 2508 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Execution timed out 5021 ms 6416 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2512 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2552 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2620 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2512 KB Output is correct
15 Correct 0 ms 2508 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 94 ms 8772 KB Output is correct
21 Correct 100 ms 7624 KB Output is correct
22 Correct 96 ms 7624 KB Output is correct
23 Correct 96 ms 8448 KB Output is correct
24 Correct 96 ms 7624 KB Output is correct
25 Correct 98 ms 7632 KB Output is correct
26 Correct 94 ms 8320 KB Output is correct
27 Correct 99 ms 7660 KB Output is correct
28 Correct 116 ms 7632 KB Output is correct
29 Correct 133 ms 7632 KB Output is correct
30 Correct 96 ms 7860 KB Output is correct
31 Correct 95 ms 8900 KB Output is correct
32 Correct 96 ms 7620 KB Output is correct
33 Correct 95 ms 7620 KB Output is correct
34 Correct 120 ms 7632 KB Output is correct
35 Correct 96 ms 8168 KB Output is correct
36 Execution timed out 5047 ms 8656 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2512 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2552 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2620 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2512 KB Output is correct
15 Correct 0 ms 2508 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 94 ms 8772 KB Output is correct
21 Correct 100 ms 7624 KB Output is correct
22 Correct 96 ms 7624 KB Output is correct
23 Correct 96 ms 8448 KB Output is correct
24 Correct 96 ms 7624 KB Output is correct
25 Correct 98 ms 7632 KB Output is correct
26 Correct 94 ms 8320 KB Output is correct
27 Correct 99 ms 7660 KB Output is correct
28 Correct 116 ms 7632 KB Output is correct
29 Correct 133 ms 7632 KB Output is correct
30 Correct 96 ms 7860 KB Output is correct
31 Correct 95 ms 8900 KB Output is correct
32 Correct 96 ms 7620 KB Output is correct
33 Correct 95 ms 7620 KB Output is correct
34 Correct 120 ms 7632 KB Output is correct
35 Correct 96 ms 8168 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2512 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Execution timed out 5058 ms 7776 KB Time limit exceeded
40 Halted 0 ms 0 KB -