Submission #561130

# Submission time Handle Problem Language Result Execution time Memory
561130 2022-05-12T10:03:51 Z two_sides Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
2406 ms 27480 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 ?
        -1 : (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 + 1 : (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:62:50: warning: narrowing conversion of '((r == m) ? (1.0e+9 + (double)1) : (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 + 1 : (grp[r].w + grp[i].w + 1) / 2};
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 260 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 260 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2163 ms 6584 KB Output is correct
21 Correct 1189 ms 4992 KB Output is correct
22 Correct 1278 ms 5004 KB Output is correct
23 Correct 1461 ms 4988 KB Output is correct
24 Correct 1880 ms 4996 KB Output is correct
25 Correct 2219 ms 4988 KB Output is correct
26 Correct 2116 ms 6708 KB Output is correct
27 Correct 2115 ms 6828 KB Output is correct
28 Correct 2127 ms 6708 KB Output is correct
29 Correct 2162 ms 6644 KB Output is correct
30 Correct 2145 ms 6720 KB Output is correct
31 Correct 2132 ms 6696 KB Output is correct
32 Correct 2105 ms 6856 KB Output is correct
33 Correct 2143 ms 6584 KB Output is correct
34 Correct 2149 ms 6688 KB Output is correct
35 Correct 2120 ms 6668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1502 ms 15980 KB Output is correct
5 Correct 1477 ms 16016 KB Output is correct
6 Correct 1458 ms 15980 KB Output is correct
7 Correct 899 ms 17908 KB Output is correct
8 Correct 760 ms 18016 KB Output is correct
9 Correct 670 ms 18084 KB Output is correct
10 Correct 1459 ms 16104 KB Output is correct
11 Correct 733 ms 18060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 260 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 214 ms 21912 KB Output is correct
21 Correct 238 ms 20076 KB Output is correct
22 Correct 205 ms 22284 KB Output is correct
23 Correct 197 ms 22296 KB Output is correct
24 Correct 210 ms 22192 KB Output is correct
25 Correct 239 ms 22252 KB Output is correct
26 Correct 222 ms 22124 KB Output is correct
27 Correct 206 ms 22296 KB Output is correct
28 Correct 215 ms 22120 KB Output is correct
29 Correct 216 ms 22276 KB Output is correct
30 Correct 221 ms 22232 KB Output is correct
31 Correct 204 ms 22116 KB Output is correct
32 Correct 204 ms 22732 KB Output is correct
33 Correct 212 ms 22076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 260 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2163 ms 6584 KB Output is correct
21 Correct 1189 ms 4992 KB Output is correct
22 Correct 1278 ms 5004 KB Output is correct
23 Correct 1461 ms 4988 KB Output is correct
24 Correct 1880 ms 4996 KB Output is correct
25 Correct 2219 ms 4988 KB Output is correct
26 Correct 2116 ms 6708 KB Output is correct
27 Correct 2115 ms 6828 KB Output is correct
28 Correct 2127 ms 6708 KB Output is correct
29 Correct 2162 ms 6644 KB Output is correct
30 Correct 2145 ms 6720 KB Output is correct
31 Correct 2132 ms 6696 KB Output is correct
32 Correct 2105 ms 6856 KB Output is correct
33 Correct 2143 ms 6584 KB Output is correct
34 Correct 2149 ms 6688 KB Output is correct
35 Correct 2120 ms 6668 KB Output is correct
36 Correct 2219 ms 7212 KB Output is correct
37 Correct 1189 ms 7136 KB Output is correct
38 Correct 1263 ms 7128 KB Output is correct
39 Correct 1478 ms 7020 KB Output is correct
40 Correct 1851 ms 6604 KB Output is correct
41 Correct 2245 ms 7128 KB Output is correct
42 Correct 2106 ms 7012 KB Output is correct
43 Correct 2136 ms 7132 KB Output is correct
44 Correct 2158 ms 7084 KB Output is correct
45 Correct 2166 ms 7068 KB Output is correct
46 Correct 2210 ms 7200 KB Output is correct
47 Correct 2211 ms 7008 KB Output is correct
48 Correct 2182 ms 7232 KB Output is correct
49 Correct 2142 ms 6996 KB Output is correct
50 Correct 2156 ms 7028 KB Output is correct
51 Correct 2164 ms 6752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 260 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2163 ms 6584 KB Output is correct
21 Correct 1189 ms 4992 KB Output is correct
22 Correct 1278 ms 5004 KB Output is correct
23 Correct 1461 ms 4988 KB Output is correct
24 Correct 1880 ms 4996 KB Output is correct
25 Correct 2219 ms 4988 KB Output is correct
26 Correct 2116 ms 6708 KB Output is correct
27 Correct 2115 ms 6828 KB Output is correct
28 Correct 2127 ms 6708 KB Output is correct
29 Correct 2162 ms 6644 KB Output is correct
30 Correct 2145 ms 6720 KB Output is correct
31 Correct 2132 ms 6696 KB Output is correct
32 Correct 2105 ms 6856 KB Output is correct
33 Correct 2143 ms 6584 KB Output is correct
34 Correct 2149 ms 6688 KB Output is correct
35 Correct 2120 ms 6668 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1502 ms 15980 KB Output is correct
40 Correct 1477 ms 16016 KB Output is correct
41 Correct 1458 ms 15980 KB Output is correct
42 Correct 899 ms 17908 KB Output is correct
43 Correct 760 ms 18016 KB Output is correct
44 Correct 670 ms 18084 KB Output is correct
45 Correct 1459 ms 16104 KB Output is correct
46 Correct 733 ms 18060 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 214 ms 21912 KB Output is correct
49 Correct 238 ms 20076 KB Output is correct
50 Correct 205 ms 22284 KB Output is correct
51 Correct 197 ms 22296 KB Output is correct
52 Correct 210 ms 22192 KB Output is correct
53 Correct 239 ms 22252 KB Output is correct
54 Correct 222 ms 22124 KB Output is correct
55 Correct 206 ms 22296 KB Output is correct
56 Correct 215 ms 22120 KB Output is correct
57 Correct 216 ms 22276 KB Output is correct
58 Correct 221 ms 22232 KB Output is correct
59 Correct 204 ms 22116 KB Output is correct
60 Correct 204 ms 22732 KB Output is correct
61 Correct 212 ms 22076 KB Output is correct
62 Correct 2219 ms 7212 KB Output is correct
63 Correct 1189 ms 7136 KB Output is correct
64 Correct 1263 ms 7128 KB Output is correct
65 Correct 1478 ms 7020 KB Output is correct
66 Correct 1851 ms 6604 KB Output is correct
67 Correct 2245 ms 7128 KB Output is correct
68 Correct 2106 ms 7012 KB Output is correct
69 Correct 2136 ms 7132 KB Output is correct
70 Correct 2158 ms 7084 KB Output is correct
71 Correct 2166 ms 7068 KB Output is correct
72 Correct 2210 ms 7200 KB Output is correct
73 Correct 2211 ms 7008 KB Output is correct
74 Correct 2182 ms 7232 KB Output is correct
75 Correct 2142 ms 6996 KB Output is correct
76 Correct 2156 ms 7028 KB Output is correct
77 Correct 2164 ms 6752 KB Output is correct
78 Correct 2377 ms 18920 KB Output is correct
79 Correct 1400 ms 25872 KB Output is correct
80 Correct 1500 ms 27292 KB Output is correct
81 Correct 1644 ms 27480 KB Output is correct
82 Correct 2031 ms 26544 KB Output is correct
83 Correct 2406 ms 25888 KB Output is correct
84 Correct 2323 ms 23316 KB Output is correct
85 Correct 2373 ms 26296 KB Output is correct
86 Correct 2297 ms 14984 KB Output is correct
87 Correct 2308 ms 20976 KB Output is correct
88 Correct 2287 ms 26212 KB Output is correct
89 Correct 2291 ms 26324 KB Output is correct
90 Correct 2315 ms 24732 KB Output is correct
91 Correct 2279 ms 15176 KB Output is correct
92 Correct 2250 ms 17948 KB Output is correct
93 Correct 2250 ms 16184 KB Output is correct