답안 #568700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568700 2022-05-26T05:38:49 Z maomao90 Reconstruction Project (JOI22_reconstruction) C++17
7 / 100
5000 ms 4720 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXM = 100005;
const int MAXN = 505;

int n, m;
iii edges[MAXM];
int q;

int rp[MAXN], rnk[MAXN];
void init() {
    REP (i, 1, n + 1) {
        rnk[i] = 1;
        rp[i] = i;
    }
}
int findp(int i) {
    if (rp[i] == i) return i;
    return rp[i] = findp(rp[i]);
}
bool join(int a, int b) {
    int pa = findp(a), pb = findp(b);
    if (pa == pb) return 0;
    if (rnk[pa] < rnk[pb]) swap(pa, pb);
    if (rnk[pa] == rnk[pb]) rnk[pa]++;
    rp[pb] = pa;
    return 1;
}

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> n >> m;
    REP (i, 0, m) {
        int a, b, w; cin >> a >> b >> w;
        edges[i] = {a, b, w};
    }
    cin >> q;
    while (q--) {
        int x; cin >> x;
        sort(edges, edges + m, [&] (iii l, iii r) {
                return abs(get<2>(l) - x) < abs(get<2>(r) - x);
                });
        init();
        ll ans = 0;
        REP (i, 0, m) {
            auto [a, b, w] = edges[i];
            if (join(a, b)) {
                ans += abs(w - x);
            }
        }
        cout << ans << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 75 ms 3108 KB Output is correct
21 Correct 84 ms 3028 KB Output is correct
22 Correct 89 ms 3024 KB Output is correct
23 Correct 80 ms 3148 KB Output is correct
24 Correct 78 ms 2992 KB Output is correct
25 Correct 81 ms 3092 KB Output is correct
26 Correct 87 ms 3144 KB Output is correct
27 Correct 80 ms 3156 KB Output is correct
28 Correct 58 ms 3152 KB Output is correct
29 Correct 71 ms 3152 KB Output is correct
30 Correct 85 ms 3172 KB Output is correct
31 Correct 82 ms 3160 KB Output is correct
32 Correct 83 ms 3148 KB Output is correct
33 Correct 80 ms 3024 KB Output is correct
34 Correct 58 ms 3296 KB Output is correct
35 Correct 61 ms 3120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 5042 ms 1496 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Execution timed out 5033 ms 4720 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 75 ms 3108 KB Output is correct
21 Correct 84 ms 3028 KB Output is correct
22 Correct 89 ms 3024 KB Output is correct
23 Correct 80 ms 3148 KB Output is correct
24 Correct 78 ms 2992 KB Output is correct
25 Correct 81 ms 3092 KB Output is correct
26 Correct 87 ms 3144 KB Output is correct
27 Correct 80 ms 3156 KB Output is correct
28 Correct 58 ms 3152 KB Output is correct
29 Correct 71 ms 3152 KB Output is correct
30 Correct 85 ms 3172 KB Output is correct
31 Correct 82 ms 3160 KB Output is correct
32 Correct 83 ms 3148 KB Output is correct
33 Correct 80 ms 3024 KB Output is correct
34 Correct 58 ms 3296 KB Output is correct
35 Correct 61 ms 3120 KB Output is correct
36 Execution timed out 5085 ms 3396 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 75 ms 3108 KB Output is correct
21 Correct 84 ms 3028 KB Output is correct
22 Correct 89 ms 3024 KB Output is correct
23 Correct 80 ms 3148 KB Output is correct
24 Correct 78 ms 2992 KB Output is correct
25 Correct 81 ms 3092 KB Output is correct
26 Correct 87 ms 3144 KB Output is correct
27 Correct 80 ms 3156 KB Output is correct
28 Correct 58 ms 3152 KB Output is correct
29 Correct 71 ms 3152 KB Output is correct
30 Correct 85 ms 3172 KB Output is correct
31 Correct 82 ms 3160 KB Output is correct
32 Correct 83 ms 3148 KB Output is correct
33 Correct 80 ms 3024 KB Output is correct
34 Correct 58 ms 3296 KB Output is correct
35 Correct 61 ms 3120 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Execution timed out 5042 ms 1496 KB Time limit exceeded
40 Halted 0 ms 0 KB -