Submission #561128

# Submission time Handle Problem Language Result Execution time Memory
561128 2022-05-12T10:00:27 Z two_sides Reconstruction Project (JOI22_reconstruction) C++17
7 / 100
1699 ms 29512 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 505;
const int M = 100005;

struct edge {
    int u, v, w;
    
    bool operator < (const edge &o) const {
        return w < o.w;
    }
};

struct disjoint {
    int par[N];
    
    void reset() {
        iota(par, par + N, 0);
    }
    
    int find(int u) {
        if (par[u] == u) return u;
        return par[u] = find(par[u]);
    }
    
    void unite(int u, int v) {
        par[find(v)] = find(u);
    }
    
    bool same(int u, int v) {
        return find(u) == find(v);
    }
} dsu;

edge grp[M], event[M * 3];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++)
        cin >> grp[i].u >> grp[i].v >> grp[i].w;
    sort(grp, grp + m);
    for (int i = 0; i < m; i++) {
        int l = i - 1, r = i + 1;
        dsu.reset();
        while (l >= 0) {
            dsu.unite(grp[l].u, grp[l].v);
            if (dsu.same(grp[i].u, grp[i].v)) break;
            l--;
        }
        dsu.reset();
        while (r < m) {
            dsu.unite(grp[r].u, grp[r].v);
            if (dsu.same(grp[i].u, grp[i].v)) break;
            r++;
        }
        event[i * 3] = {grp[i].w, -1, l < 0 ?
        -1e9 : (grp[l].w + grp[i].w + 1) / 2};
        event[i * 3 + 1] = {-2 * grp[i].w, 2, grp[i].w};
        event[i * 3 + 2] = {grp[i].w, -1, r == m ?
        1e9 : (grp[r].w + grp[i].w + 1) / 2};
    }
    sort(event, event + m * 3);
    int q; cin >> q;
    int mul = 0; long long add = 0;
    for (int i = 0, j = 0; i < q; i++) {
        long long cur; cin >> cur;
        while (j < 3 * m && event[j].w <= cur) {
            add += event[j].u;
            mul += event[j++].v;
        }
        cout << add + cur * mul << '\n';
    }
}

Compilation message

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:59:45: warning: narrowing conversion of '((l < 0) ? -1.0e+9 : (double)((grp[l].edge::w + grp[i].edge::w + 1) / 2))' from 'double' to 'int' [-Wnarrowing]
   59 |         event[i * 3] = {grp[i].w, -1, l < 0 ?
      |                                       ~~~~~~^
   60 |         -1e9 : (grp[l].w + grp[i].w + 1) / 2};
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
reconstruction.cpp:62:50: warning: narrowing conversion of '((r == m) ? 1.0e+9 : (double)((grp[r].edge::w + grp[i].edge::w + 1) / 2))' from 'double' to 'int' [-Wnarrowing]
   62 |         event[i * 3 + 2] = {grp[i].w, -1, r == m ?
      |                                           ~~~~~~~^
   63 |         1e9 : (grp[r].w + grp[i].w + 1) / 2};
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1699 ms 27372 KB Output is correct
5 Correct 1636 ms 27296 KB Output is correct
6 Correct 1688 ms 27236 KB Output is correct
7 Correct 964 ms 29260 KB Output is correct
8 Correct 797 ms 29464 KB Output is correct
9 Correct 665 ms 29512 KB Output is correct
10 Correct 1525 ms 27432 KB Output is correct
11 Correct 760 ms 29508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -