Submission #906682

# Submission time Handle Problem Language Result Execution time Memory
906682 2024-01-14T17:18:12 Z setytousi Reconstruction Project (JOI22_reconstruction) C++17
42 / 100
1658 ms 53392 KB
#include<bits/stdc++.h>
using namespace std;
#define int ll
		 
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
		 
const ll MAXN = 3e5 + 6;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;
const int s = 2048;

#define fast_io     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io     freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define pb          push_back
#define F           first
#define S           second
#define Sz(x)       int((x).size())
#define all(x)      (x).begin(), (x).end()
#define cl          clear()
#define endll       '\n'


int n, m, mn[MAXN], mx[MAXN], par[MAXN], cnt[MAXN];
ll ans[MAXN], out[MAXN];
vector<pair<int, pii>> edg;
vector<pii> query;

void init(){
    for (int i = 1; i <= n; i++) par[i] = i;
}
int root(int v){
    return (par[v] == v ? v : par[v] = root(par[v]));
}
void merge(int v, int u){
    v = root(v);
    u = root(u);
    if (v == u) return;
    par[v] = u;
}

int32_t main(){
    fast_io;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        int v, u, w;
        cin >> v >> u >> w; 
        if (v > u) swap(v, u);
        edg.pb({w, {v, u}});
    }
    fill(mx, mx + m, INF);
    fill(mn, mn + m, -INF);
    sort(all(edg));
    for (int i = 0; i < m; i++){
        init();
        for (int j = i - 1; j >= 0; j--){
            merge(edg[j].S.F, edg[j].S.S);
            if (root(edg[i].S.F) == root(edg[i].S.S)){
                mn[i] = (edg[i].F + edg[j].F) / 2 + ((edg[i].F + edg[j].F) % 2);
                break;
            }
        }
    }
    for (int i = 0; i < m; i++){
        init();
        for (int j = i + 1; j < m; j++){
            merge(edg[j].S.F, edg[j].S.S);
            if (root(edg[i].S.S) == root(edg[i].S.F)){
                mx[i] = (edg[i].F + edg[j].F) / 2 - ((edg[i].F + edg[j].F + 1) % 2) + 1;
                break;
            }
        }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++){
        int x;
        cin >> x;
        query.pb({x, i});
    }
    sort(all(query));
    for (int i = 0; i < m; i++){
        // cout << mn[i] << ' ' << mx[i] << endll;
        int val = edg[i].F;
        mn[i] = lower_bound(all(query), make_pair(mn[i], 0ll)) - query.begin();
        int mid = lower_bound(all(query), make_pair(val, 0ll)) - query.begin();
        mx[i] = lower_bound(all(query), make_pair(mx[i], 0ll)) - query.begin();
        ans[mn[i]] -= val;
        cnt[mn[i]]++;
        ans[mid] += 2 * val;
        cnt[mid]--;
        ans[mx[i]] -= val;
    }
    for (int i = 0; i < q; i++){
        if (i) ans[i] += ans[i - 1], cnt[i] += cnt[i - 1];
        out[query[i].S] = ans[i] + cnt[i] * query[i].F - (n - 1 - cnt[i]) * query[i].F;
    }
    for (int i = 0; i < q; i++) cout << -out[i] << endll;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 3 ms 10584 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 3 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 3 ms 10584 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 3 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 1524 ms 13228 KB Output is correct
21 Correct 759 ms 13228 KB Output is correct
22 Correct 841 ms 13216 KB Output is correct
23 Correct 1027 ms 13224 KB Output is correct
24 Correct 1338 ms 13224 KB Output is correct
25 Correct 1611 ms 13220 KB Output is correct
26 Correct 1537 ms 13496 KB Output is correct
27 Correct 1528 ms 13364 KB Output is correct
28 Correct 1507 ms 13224 KB Output is correct
29 Correct 961 ms 13244 KB Output is correct
30 Correct 1525 ms 13224 KB Output is correct
31 Correct 1527 ms 13224 KB Output is correct
32 Correct 1520 ms 13756 KB Output is correct
33 Correct 1518 ms 13224 KB Output is correct
34 Correct 664 ms 13224 KB Output is correct
35 Correct 1512 ms 12988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10584 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Incorrect 920 ms 53392 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 3 ms 10584 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 3 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10720 KB Output is correct
20 Incorrect 189 ms 49804 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 3 ms 10584 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 3 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 1524 ms 13228 KB Output is correct
21 Correct 759 ms 13228 KB Output is correct
22 Correct 841 ms 13216 KB Output is correct
23 Correct 1027 ms 13224 KB Output is correct
24 Correct 1338 ms 13224 KB Output is correct
25 Correct 1611 ms 13220 KB Output is correct
26 Correct 1537 ms 13496 KB Output is correct
27 Correct 1528 ms 13364 KB Output is correct
28 Correct 1507 ms 13224 KB Output is correct
29 Correct 961 ms 13244 KB Output is correct
30 Correct 1525 ms 13224 KB Output is correct
31 Correct 1527 ms 13224 KB Output is correct
32 Correct 1520 ms 13756 KB Output is correct
33 Correct 1518 ms 13224 KB Output is correct
34 Correct 664 ms 13224 KB Output is correct
35 Correct 1512 ms 12988 KB Output is correct
36 Correct 1541 ms 14408 KB Output is correct
37 Correct 770 ms 14268 KB Output is correct
38 Correct 849 ms 14404 KB Output is correct
39 Correct 1028 ms 14248 KB Output is correct
40 Correct 1335 ms 14308 KB Output is correct
41 Correct 1658 ms 14248 KB Output is correct
42 Correct 1546 ms 14784 KB Output is correct
43 Correct 1532 ms 14248 KB Output is correct
44 Correct 1546 ms 14240 KB Output is correct
45 Correct 958 ms 14248 KB Output is correct
46 Correct 1544 ms 14884 KB Output is correct
47 Correct 1534 ms 14240 KB Output is correct
48 Correct 1553 ms 14276 KB Output is correct
49 Correct 1552 ms 14252 KB Output is correct
50 Correct 686 ms 14524 KB Output is correct
51 Correct 1572 ms 14244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 3 ms 10584 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 3 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 1524 ms 13228 KB Output is correct
21 Correct 759 ms 13228 KB Output is correct
22 Correct 841 ms 13216 KB Output is correct
23 Correct 1027 ms 13224 KB Output is correct
24 Correct 1338 ms 13224 KB Output is correct
25 Correct 1611 ms 13220 KB Output is correct
26 Correct 1537 ms 13496 KB Output is correct
27 Correct 1528 ms 13364 KB Output is correct
28 Correct 1507 ms 13224 KB Output is correct
29 Correct 961 ms 13244 KB Output is correct
30 Correct 1525 ms 13224 KB Output is correct
31 Correct 1527 ms 13224 KB Output is correct
32 Correct 1520 ms 13756 KB Output is correct
33 Correct 1518 ms 13224 KB Output is correct
34 Correct 664 ms 13224 KB Output is correct
35 Correct 1512 ms 12988 KB Output is correct
36 Correct 2 ms 10584 KB Output is correct
37 Correct 2 ms 10584 KB Output is correct
38 Correct 2 ms 10588 KB Output is correct
39 Incorrect 920 ms 53392 KB Output isn't correct
40 Halted 0 ms 0 KB -