답안 #779994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779994 2023-07-12T04:56:19 Z eltu0815 Reconstruction Project (JOI22_reconstruction) C++14
100 / 100
750 ms 35784 KB
#include <bits/stdc++.h>
#define MAX 500005
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define inf (1987654321)
 
using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
 
int n, m, q;
int parent[505], E[100005], invE[100005];
vector<pair<ll, pii> > edge;
vector<pair<ll, pll> > coef;
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n >> m;
    edge.push_back({-(int)(1e9), {0, 0}});
    for(int i = 1; i <= m; ++i) {
        int a, b, w; cin >> a >> b >> w;
        edge.push_back({w, {a, b}});
    }
    sort(edge.begin(), edge.end());
    
    auto getParent = [&](auto&& self, int node) -> int {
        if(parent[node] == node) return node;
        return parent[node] = self(self, parent[node]);
    };
    
    auto unionParent = [&](int u, int v) -> void {
        u = getParent(getParent, u);
        v = getParent(getParent, v);
        if(u < v) swap(u, v);
        parent[v] = u;
    };
    
    for(int i = 1; i <= m; ++i) {
        int a = edge[i].second.first, b = edge[i].second.second;
        int p = i - 1;
        for(int j = 1; j <= n; ++j) parent[j] = j;
        while(p) {
            unionParent(edge[p].second.first, edge[p].second.second);
            if(getParent(getParent, a) == getParent(getParent, b)) break;
            --p;
        }
        E[i] = p + 1;
    }
    
    for(int i = 1; i <= m; ++i) invE[i] = m;
    for(int i = 1; i <= m; ++i) invE[E[i] - 1] = i - 1;
    
    for(int i = 1; i <= m; ++i) {
        coef.push_back({edge[i].first, {2, -2 * edge[i].first}});
        coef.push_back({(edge[i].first + edge[E[i] - 1].first)/2 + 1, {-1, edge[i].first}});
        if(invE[i] != m) coef.push_back({(edge[i].first + edge[invE[i] + 1].first)/2 + 1, {-1, edge[i].first}});
    }
    sort(coef.begin(), coef.end());
    
    cin >> q;
    int i = 0; ll a = 0, b = 0;
    while(q--) {
        ll x; cin >> x;
        while(i < (int)coef.size() && coef[i].first <= x) {
            a += 1ll * coef[i].second.first;
            b += 1ll * coef[i].second.second;
            ++i;
        }
        cout << a * x + b << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 244 KB Output is correct
3 Correct 1 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 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 244 KB Output is correct
3 Correct 1 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 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 1 ms 400 KB Output is correct
20 Correct 579 ms 16488 KB Output is correct
21 Correct 374 ms 18172 KB Output is correct
22 Correct 433 ms 18200 KB Output is correct
23 Correct 489 ms 18188 KB Output is correct
24 Correct 538 ms 18128 KB Output is correct
25 Correct 568 ms 18244 KB Output is correct
26 Correct 584 ms 18148 KB Output is correct
27 Correct 576 ms 18148 KB Output is correct
28 Correct 592 ms 18140 KB Output is correct
29 Correct 285 ms 18228 KB Output is correct
30 Correct 575 ms 18136 KB Output is correct
31 Correct 597 ms 18208 KB Output is correct
32 Correct 578 ms 18236 KB Output is correct
33 Correct 633 ms 18192 KB Output is correct
34 Correct 219 ms 18356 KB Output is correct
35 Correct 620 ms 18208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 620 ms 22252 KB Output is correct
5 Correct 598 ms 33660 KB Output is correct
6 Correct 621 ms 33660 KB Output is correct
7 Correct 439 ms 35452 KB Output is correct
8 Correct 375 ms 35688 KB Output is correct
9 Correct 355 ms 35712 KB Output is correct
10 Correct 548 ms 33872 KB Output is correct
11 Correct 374 ms 35784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 244 KB Output is correct
3 Correct 1 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 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 177 ms 12680 KB Output is correct
21 Correct 171 ms 22484 KB Output is correct
22 Correct 164 ms 22480 KB Output is correct
23 Correct 195 ms 22708 KB Output is correct
24 Correct 166 ms 22368 KB Output is correct
25 Correct 156 ms 22348 KB Output is correct
26 Correct 178 ms 22348 KB Output is correct
27 Correct 175 ms 22392 KB Output is correct
28 Correct 179 ms 22392 KB Output is correct
29 Correct 173 ms 22396 KB Output is correct
30 Correct 159 ms 22476 KB Output is correct
31 Correct 164 ms 22300 KB Output is correct
32 Correct 179 ms 22980 KB Output is correct
33 Correct 183 ms 22292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 244 KB Output is correct
3 Correct 1 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 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 1 ms 400 KB Output is correct
20 Correct 579 ms 16488 KB Output is correct
21 Correct 374 ms 18172 KB Output is correct
22 Correct 433 ms 18200 KB Output is correct
23 Correct 489 ms 18188 KB Output is correct
24 Correct 538 ms 18128 KB Output is correct
25 Correct 568 ms 18244 KB Output is correct
26 Correct 584 ms 18148 KB Output is correct
27 Correct 576 ms 18148 KB Output is correct
28 Correct 592 ms 18140 KB Output is correct
29 Correct 285 ms 18228 KB Output is correct
30 Correct 575 ms 18136 KB Output is correct
31 Correct 597 ms 18208 KB Output is correct
32 Correct 578 ms 18236 KB Output is correct
33 Correct 633 ms 18192 KB Output is correct
34 Correct 219 ms 18356 KB Output is correct
35 Correct 620 ms 18208 KB Output is correct
36 Correct 577 ms 18384 KB Output is correct
37 Correct 395 ms 18532 KB Output is correct
38 Correct 427 ms 18384 KB Output is correct
39 Correct 476 ms 18436 KB Output is correct
40 Correct 565 ms 18432 KB Output is correct
41 Correct 586 ms 18368 KB Output is correct
42 Correct 602 ms 18492 KB Output is correct
43 Correct 599 ms 18368 KB Output is correct
44 Correct 573 ms 18328 KB Output is correct
45 Correct 289 ms 18416 KB Output is correct
46 Correct 588 ms 18352 KB Output is correct
47 Correct 583 ms 18356 KB Output is correct
48 Correct 605 ms 18408 KB Output is correct
49 Correct 590 ms 18328 KB Output is correct
50 Correct 212 ms 18508 KB Output is correct
51 Correct 595 ms 18500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 244 KB Output is correct
3 Correct 1 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 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 1 ms 400 KB Output is correct
20 Correct 579 ms 16488 KB Output is correct
21 Correct 374 ms 18172 KB Output is correct
22 Correct 433 ms 18200 KB Output is correct
23 Correct 489 ms 18188 KB Output is correct
24 Correct 538 ms 18128 KB Output is correct
25 Correct 568 ms 18244 KB Output is correct
26 Correct 584 ms 18148 KB Output is correct
27 Correct 576 ms 18148 KB Output is correct
28 Correct 592 ms 18140 KB Output is correct
29 Correct 285 ms 18228 KB Output is correct
30 Correct 575 ms 18136 KB Output is correct
31 Correct 597 ms 18208 KB Output is correct
32 Correct 578 ms 18236 KB Output is correct
33 Correct 633 ms 18192 KB Output is correct
34 Correct 219 ms 18356 KB Output is correct
35 Correct 620 ms 18208 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 620 ms 22252 KB Output is correct
40 Correct 598 ms 33660 KB Output is correct
41 Correct 621 ms 33660 KB Output is correct
42 Correct 439 ms 35452 KB Output is correct
43 Correct 375 ms 35688 KB Output is correct
44 Correct 355 ms 35712 KB Output is correct
45 Correct 548 ms 33872 KB Output is correct
46 Correct 374 ms 35784 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 177 ms 12680 KB Output is correct
49 Correct 171 ms 22484 KB Output is correct
50 Correct 164 ms 22480 KB Output is correct
51 Correct 195 ms 22708 KB Output is correct
52 Correct 166 ms 22368 KB Output is correct
53 Correct 156 ms 22348 KB Output is correct
54 Correct 178 ms 22348 KB Output is correct
55 Correct 175 ms 22392 KB Output is correct
56 Correct 179 ms 22392 KB Output is correct
57 Correct 173 ms 22396 KB Output is correct
58 Correct 159 ms 22476 KB Output is correct
59 Correct 164 ms 22300 KB Output is correct
60 Correct 179 ms 22980 KB Output is correct
61 Correct 183 ms 22292 KB Output is correct
62 Correct 577 ms 18384 KB Output is correct
63 Correct 395 ms 18532 KB Output is correct
64 Correct 427 ms 18384 KB Output is correct
65 Correct 476 ms 18436 KB Output is correct
66 Correct 565 ms 18432 KB Output is correct
67 Correct 586 ms 18368 KB Output is correct
68 Correct 602 ms 18492 KB Output is correct
69 Correct 599 ms 18368 KB Output is correct
70 Correct 573 ms 18328 KB Output is correct
71 Correct 289 ms 18416 KB Output is correct
72 Correct 588 ms 18352 KB Output is correct
73 Correct 583 ms 18356 KB Output is correct
74 Correct 605 ms 18408 KB Output is correct
75 Correct 590 ms 18328 KB Output is correct
76 Correct 212 ms 18508 KB Output is correct
77 Correct 595 ms 18500 KB Output is correct
78 Correct 733 ms 32656 KB Output is correct
79 Correct 528 ms 34692 KB Output is correct
80 Correct 550 ms 33568 KB Output is correct
81 Correct 599 ms 33584 KB Output is correct
82 Correct 691 ms 32840 KB Output is correct
83 Correct 750 ms 32744 KB Output is correct
84 Correct 712 ms 32664 KB Output is correct
85 Correct 720 ms 32716 KB Output is correct
86 Correct 707 ms 32616 KB Output is correct
87 Correct 435 ms 34288 KB Output is correct
88 Correct 727 ms 32584 KB Output is correct
89 Correct 724 ms 32616 KB Output is correct
90 Correct 746 ms 32812 KB Output is correct
91 Correct 726 ms 32552 KB Output is correct
92 Correct 355 ms 35468 KB Output is correct
93 Correct 732 ms 33732 KB Output is correct