Submission #796178

# Submission time Handle Problem Language Result Execution time Memory
796178 2023-07-28T07:27:10 Z 이동현(#10071) Security Guard (JOI23_guard) C++17
37 / 100
192 ms 19732 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;

const int NS = (int)2e5 + 4;
int n, m, q;
int a[NS], srt[NS], chk[NS];
vector<int> way[NS];

struct Dsu{
    int n;
    vector<int> pr;
    Dsu(int m){
        n = m + 4;
        pr.resize(n);
        iota(pr.begin(), pr.end(), 0);
    }

    int fd(int x){
        return (x == pr[x] ? x : pr[x] = fd(pr[x]));
    }

    bool unite(int x, int y){
        x = fd(x), y = fd(y);
        if(x == y){
            return false;
        }
        pr[y] = x;
        return true;
    }
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m >> q;
    int ans = 0;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 1; i <= m; ++i){
        int x, y;
        cin >> x >> y;
        way[x].push_back(y);
        way[y].push_back(x);
        ans += min(a[x], a[y]);
    }

    iota(srt, srt + NS, 0);
    sort(srt + 1, srt + n + 1, [&](int x, int y){return a[x] < a[y];});

    Dsu uni(n + 4);

    int gr = 0;
    for(int i = 1; i < n; ++i){
        int now = srt[i];
        
        ++gr;
        chk[now] = 1;
        for(auto&nxt:way[now]){
            if(chk[nxt]){
                gr -= uni.unite(now, nxt);
            }
        }

        // cout << now << ' ' << gr << endl;

        ans += gr * (a[srt[i + 1]] - a[srt[i]]);
    }

    cout << ans << '\n';
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 77 ms 17656 KB Output is correct
3 Correct 77 ms 17512 KB Output is correct
4 Correct 71 ms 17524 KB Output is correct
5 Correct 70 ms 17484 KB Output is correct
6 Correct 65 ms 17464 KB Output is correct
7 Correct 67 ms 17516 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 77 ms 17656 KB Output is correct
3 Correct 77 ms 17512 KB Output is correct
4 Correct 71 ms 17524 KB Output is correct
5 Correct 70 ms 17484 KB Output is correct
6 Correct 65 ms 17464 KB Output is correct
7 Correct 67 ms 17516 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 104 ms 17476 KB Output is correct
11 Correct 71 ms 17468 KB Output is correct
12 Correct 72 ms 17484 KB Output is correct
13 Correct 68 ms 17472 KB Output is correct
14 Correct 97 ms 17472 KB Output is correct
15 Correct 104 ms 17600 KB Output is correct
16 Correct 100 ms 17448 KB Output is correct
17 Correct 102 ms 17484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 77 ms 17656 KB Output is correct
3 Correct 77 ms 17512 KB Output is correct
4 Correct 71 ms 17524 KB Output is correct
5 Correct 70 ms 17484 KB Output is correct
6 Correct 65 ms 17464 KB Output is correct
7 Correct 67 ms 17516 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 104 ms 17476 KB Output is correct
11 Correct 71 ms 17468 KB Output is correct
12 Correct 72 ms 17484 KB Output is correct
13 Correct 68 ms 17472 KB Output is correct
14 Correct 97 ms 17472 KB Output is correct
15 Correct 104 ms 17600 KB Output is correct
16 Correct 100 ms 17448 KB Output is correct
17 Correct 102 ms 17484 KB Output is correct
18 Correct 3 ms 6484 KB Output is correct
19 Correct 126 ms 18548 KB Output is correct
20 Correct 121 ms 18528 KB Output is correct
21 Correct 130 ms 18508 KB Output is correct
22 Correct 131 ms 18692 KB Output is correct
23 Correct 118 ms 19240 KB Output is correct
24 Correct 103 ms 19512 KB Output is correct
25 Correct 108 ms 19128 KB Output is correct
26 Correct 118 ms 19120 KB Output is correct
27 Correct 94 ms 19080 KB Output is correct
28 Correct 160 ms 17884 KB Output is correct
29 Correct 117 ms 18216 KB Output is correct
30 Correct 114 ms 18916 KB Output is correct
31 Correct 107 ms 18992 KB Output is correct
32 Correct 143 ms 19200 KB Output is correct
33 Correct 117 ms 19732 KB Output is correct
34 Correct 146 ms 18592 KB Output is correct
35 Correct 135 ms 19704 KB Output is correct
36 Correct 90 ms 19572 KB Output is correct
37 Correct 93 ms 19552 KB Output is correct
38 Correct 140 ms 19268 KB Output is correct
39 Correct 102 ms 19500 KB Output is correct
40 Correct 110 ms 19208 KB Output is correct
41 Correct 116 ms 17476 KB Output is correct
42 Correct 115 ms 17528 KB Output is correct
43 Correct 118 ms 18800 KB Output is correct
44 Correct 142 ms 18652 KB Output is correct
45 Correct 186 ms 18652 KB Output is correct
46 Correct 109 ms 18732 KB Output is correct
47 Correct 127 ms 18704 KB Output is correct
48 Correct 121 ms 18636 KB Output is correct
49 Correct 192 ms 18680 KB Output is correct
50 Correct 116 ms 18692 KB Output is correct
51 Correct 113 ms 18736 KB Output is correct
52 Correct 93 ms 18692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 77 ms 17656 KB Output is correct
3 Correct 77 ms 17512 KB Output is correct
4 Correct 71 ms 17524 KB Output is correct
5 Correct 70 ms 17484 KB Output is correct
6 Correct 65 ms 17464 KB Output is correct
7 Correct 67 ms 17516 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 104 ms 17476 KB Output is correct
11 Correct 71 ms 17468 KB Output is correct
12 Correct 72 ms 17484 KB Output is correct
13 Correct 68 ms 17472 KB Output is correct
14 Correct 97 ms 17472 KB Output is correct
15 Correct 104 ms 17600 KB Output is correct
16 Correct 100 ms 17448 KB Output is correct
17 Correct 102 ms 17484 KB Output is correct
18 Correct 3 ms 6484 KB Output is correct
19 Correct 126 ms 18548 KB Output is correct
20 Correct 121 ms 18528 KB Output is correct
21 Correct 130 ms 18508 KB Output is correct
22 Correct 131 ms 18692 KB Output is correct
23 Correct 118 ms 19240 KB Output is correct
24 Correct 103 ms 19512 KB Output is correct
25 Correct 108 ms 19128 KB Output is correct
26 Correct 118 ms 19120 KB Output is correct
27 Correct 94 ms 19080 KB Output is correct
28 Correct 160 ms 17884 KB Output is correct
29 Correct 117 ms 18216 KB Output is correct
30 Correct 114 ms 18916 KB Output is correct
31 Correct 107 ms 18992 KB Output is correct
32 Correct 143 ms 19200 KB Output is correct
33 Correct 117 ms 19732 KB Output is correct
34 Correct 146 ms 18592 KB Output is correct
35 Correct 135 ms 19704 KB Output is correct
36 Correct 90 ms 19572 KB Output is correct
37 Correct 93 ms 19552 KB Output is correct
38 Correct 140 ms 19268 KB Output is correct
39 Correct 102 ms 19500 KB Output is correct
40 Correct 110 ms 19208 KB Output is correct
41 Correct 116 ms 17476 KB Output is correct
42 Correct 115 ms 17528 KB Output is correct
43 Correct 118 ms 18800 KB Output is correct
44 Correct 142 ms 18652 KB Output is correct
45 Correct 186 ms 18652 KB Output is correct
46 Correct 109 ms 18732 KB Output is correct
47 Correct 127 ms 18704 KB Output is correct
48 Correct 121 ms 18636 KB Output is correct
49 Correct 192 ms 18680 KB Output is correct
50 Correct 116 ms 18692 KB Output is correct
51 Correct 113 ms 18736 KB Output is correct
52 Correct 93 ms 18692 KB Output is correct
53 Incorrect 4 ms 6484 KB Output isn't correct
54 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Incorrect 3 ms 6484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Incorrect 3 ms 6484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 77 ms 17656 KB Output is correct
3 Correct 77 ms 17512 KB Output is correct
4 Correct 71 ms 17524 KB Output is correct
5 Correct 70 ms 17484 KB Output is correct
6 Correct 65 ms 17464 KB Output is correct
7 Correct 67 ms 17516 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 104 ms 17476 KB Output is correct
11 Correct 71 ms 17468 KB Output is correct
12 Correct 72 ms 17484 KB Output is correct
13 Correct 68 ms 17472 KB Output is correct
14 Correct 97 ms 17472 KB Output is correct
15 Correct 104 ms 17600 KB Output is correct
16 Correct 100 ms 17448 KB Output is correct
17 Correct 102 ms 17484 KB Output is correct
18 Correct 3 ms 6484 KB Output is correct
19 Correct 126 ms 18548 KB Output is correct
20 Correct 121 ms 18528 KB Output is correct
21 Correct 130 ms 18508 KB Output is correct
22 Correct 131 ms 18692 KB Output is correct
23 Correct 118 ms 19240 KB Output is correct
24 Correct 103 ms 19512 KB Output is correct
25 Correct 108 ms 19128 KB Output is correct
26 Correct 118 ms 19120 KB Output is correct
27 Correct 94 ms 19080 KB Output is correct
28 Correct 160 ms 17884 KB Output is correct
29 Correct 117 ms 18216 KB Output is correct
30 Correct 114 ms 18916 KB Output is correct
31 Correct 107 ms 18992 KB Output is correct
32 Correct 143 ms 19200 KB Output is correct
33 Correct 117 ms 19732 KB Output is correct
34 Correct 146 ms 18592 KB Output is correct
35 Correct 135 ms 19704 KB Output is correct
36 Correct 90 ms 19572 KB Output is correct
37 Correct 93 ms 19552 KB Output is correct
38 Correct 140 ms 19268 KB Output is correct
39 Correct 102 ms 19500 KB Output is correct
40 Correct 110 ms 19208 KB Output is correct
41 Correct 116 ms 17476 KB Output is correct
42 Correct 115 ms 17528 KB Output is correct
43 Correct 118 ms 18800 KB Output is correct
44 Correct 142 ms 18652 KB Output is correct
45 Correct 186 ms 18652 KB Output is correct
46 Correct 109 ms 18732 KB Output is correct
47 Correct 127 ms 18704 KB Output is correct
48 Correct 121 ms 18636 KB Output is correct
49 Correct 192 ms 18680 KB Output is correct
50 Correct 116 ms 18692 KB Output is correct
51 Correct 113 ms 18736 KB Output is correct
52 Correct 93 ms 18692 KB Output is correct
53 Incorrect 4 ms 6484 KB Output isn't correct
54 Halted 0 ms 0 KB -