답안 #893026

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893026 2023-12-26T11:28:26 Z alexander707070 Security Guard (JOI23_guard) C++14
50 / 100
270 ms 16232 KB
#include<bits/stdc++.h>
#define MAXN 200007
using namespace std;

struct edge{
    int from,to,cost;
};

bool cmp(edge fr,edge sc){
    return fr.cost<sc.cost;
}

int n,m,q,a,b,s[MAXN];
vector<edge> w;
long long ans;

int dsu[MAXN],sz[MAXN],maxs;

int root(int x){
    if(dsu[x]==x)return x;
    dsu[x]=root(dsu[x]);
    return dsu[x];
}

void mergev(int x,int y){
    int rootx=root(x);
    int rooty=root(y);

    if(sz[rooty]>sz[rootx])swap(rootx,rooty);
    sz[rootx]+=sz[rooty];
    dsu[rooty]=dsu[rootx];
}

int main(){

    cin>>n>>m>>q;

    for(int i=1;i<=n;i++){
        cin>>s[i];
        ans-=s[i];
        maxs=max(maxs,s[i]);

        dsu[i]=i; sz[i]=1;
    }

    for(int i=1;i<=m;i++){
        cin>>a>>b;
        w.push_back({a,b,s[a]+s[b]});
    }

    sort(w.begin(),w.end(),cmp);

    for(int i=0;i<w.size();i++){
        if(root(w[i].from)==root(w[i].to))continue;
        mergev(w[i].from,w[i].to);
        ans+=s[w[i].from]+s[w[i].to];
    }

    ans+=maxs;

    cout<<ans<<"\n";

    return 0;
}

Compilation message

guard.cpp: In function 'int main()':
guard.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i=0;i<w.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 109 ms 7992 KB Output is correct
3 Correct 131 ms 8648 KB Output is correct
4 Correct 112 ms 8004 KB Output is correct
5 Correct 112 ms 9416 KB Output is correct
6 Correct 112 ms 8136 KB Output is correct
7 Correct 116 ms 8388 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 109 ms 7992 KB Output is correct
3 Correct 131 ms 8648 KB Output is correct
4 Correct 112 ms 8004 KB Output is correct
5 Correct 112 ms 9416 KB Output is correct
6 Correct 112 ms 8136 KB Output is correct
7 Correct 116 ms 8388 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 159 ms 9604 KB Output is correct
11 Correct 146 ms 10648 KB Output is correct
12 Correct 153 ms 9788 KB Output is correct
13 Correct 143 ms 9688 KB Output is correct
14 Correct 157 ms 10184 KB Output is correct
15 Correct 158 ms 9668 KB Output is correct
16 Correct 164 ms 11244 KB Output is correct
17 Correct 158 ms 10944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 109 ms 7992 KB Output is correct
3 Correct 131 ms 8648 KB Output is correct
4 Correct 112 ms 8004 KB Output is correct
5 Correct 112 ms 9416 KB Output is correct
6 Correct 112 ms 8136 KB Output is correct
7 Correct 116 ms 8388 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 159 ms 9604 KB Output is correct
11 Correct 146 ms 10648 KB Output is correct
12 Correct 153 ms 9788 KB Output is correct
13 Correct 143 ms 9688 KB Output is correct
14 Correct 157 ms 10184 KB Output is correct
15 Correct 158 ms 9668 KB Output is correct
16 Correct 164 ms 11244 KB Output is correct
17 Correct 158 ms 10944 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 158 ms 10844 KB Output is correct
20 Correct 166 ms 10960 KB Output is correct
21 Correct 158 ms 10564 KB Output is correct
22 Correct 158 ms 10268 KB Output is correct
23 Correct 160 ms 9580 KB Output is correct
24 Correct 155 ms 10688 KB Output is correct
25 Correct 162 ms 9660 KB Output is correct
26 Correct 159 ms 9668 KB Output is correct
27 Correct 154 ms 10468 KB Output is correct
28 Correct 158 ms 9672 KB Output is correct
29 Correct 158 ms 10452 KB Output is correct
30 Correct 166 ms 9656 KB Output is correct
31 Correct 157 ms 9732 KB Output is correct
32 Correct 162 ms 10684 KB Output is correct
33 Correct 132 ms 8904 KB Output is correct
34 Correct 155 ms 11200 KB Output is correct
35 Correct 150 ms 9796 KB Output is correct
36 Correct 149 ms 9924 KB Output is correct
37 Correct 159 ms 9964 KB Output is correct
38 Correct 151 ms 9460 KB Output is correct
39 Correct 146 ms 9416 KB Output is correct
40 Correct 146 ms 10436 KB Output is correct
41 Correct 147 ms 9156 KB Output is correct
42 Correct 142 ms 9412 KB Output is correct
43 Correct 145 ms 9668 KB Output is correct
44 Correct 158 ms 10692 KB Output is correct
45 Correct 156 ms 9772 KB Output is correct
46 Correct 152 ms 9668 KB Output is correct
47 Correct 153 ms 9660 KB Output is correct
48 Correct 155 ms 10568 KB Output is correct
49 Correct 158 ms 10940 KB Output is correct
50 Correct 159 ms 9668 KB Output is correct
51 Correct 151 ms 9928 KB Output is correct
52 Correct 118 ms 8252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 109 ms 7992 KB Output is correct
3 Correct 131 ms 8648 KB Output is correct
4 Correct 112 ms 8004 KB Output is correct
5 Correct 112 ms 9416 KB Output is correct
6 Correct 112 ms 8136 KB Output is correct
7 Correct 116 ms 8388 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 159 ms 9604 KB Output is correct
11 Correct 146 ms 10648 KB Output is correct
12 Correct 153 ms 9788 KB Output is correct
13 Correct 143 ms 9688 KB Output is correct
14 Correct 157 ms 10184 KB Output is correct
15 Correct 158 ms 9668 KB Output is correct
16 Correct 164 ms 11244 KB Output is correct
17 Correct 158 ms 10944 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 158 ms 10844 KB Output is correct
20 Correct 166 ms 10960 KB Output is correct
21 Correct 158 ms 10564 KB Output is correct
22 Correct 158 ms 10268 KB Output is correct
23 Correct 160 ms 9580 KB Output is correct
24 Correct 155 ms 10688 KB Output is correct
25 Correct 162 ms 9660 KB Output is correct
26 Correct 159 ms 9668 KB Output is correct
27 Correct 154 ms 10468 KB Output is correct
28 Correct 158 ms 9672 KB Output is correct
29 Correct 158 ms 10452 KB Output is correct
30 Correct 166 ms 9656 KB Output is correct
31 Correct 157 ms 9732 KB Output is correct
32 Correct 162 ms 10684 KB Output is correct
33 Correct 132 ms 8904 KB Output is correct
34 Correct 155 ms 11200 KB Output is correct
35 Correct 150 ms 9796 KB Output is correct
36 Correct 149 ms 9924 KB Output is correct
37 Correct 159 ms 9964 KB Output is correct
38 Correct 151 ms 9460 KB Output is correct
39 Correct 146 ms 9416 KB Output is correct
40 Correct 146 ms 10436 KB Output is correct
41 Correct 147 ms 9156 KB Output is correct
42 Correct 142 ms 9412 KB Output is correct
43 Correct 145 ms 9668 KB Output is correct
44 Correct 158 ms 10692 KB Output is correct
45 Correct 156 ms 9772 KB Output is correct
46 Correct 152 ms 9668 KB Output is correct
47 Correct 153 ms 9660 KB Output is correct
48 Correct 155 ms 10568 KB Output is correct
49 Correct 158 ms 10940 KB Output is correct
50 Correct 159 ms 9668 KB Output is correct
51 Correct 151 ms 9928 KB Output is correct
52 Correct 118 ms 8252 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 162 ms 10952 KB Output is correct
55 Correct 165 ms 9916 KB Output is correct
56 Correct 193 ms 15780 KB Output is correct
57 Correct 263 ms 16076 KB Output is correct
58 Correct 269 ms 15808 KB Output is correct
59 Correct 258 ms 16232 KB Output is correct
60 Correct 205 ms 15804 KB Output is correct
61 Correct 262 ms 15208 KB Output is correct
62 Correct 261 ms 15676 KB Output is correct
63 Correct 168 ms 9852 KB Output is correct
64 Correct 221 ms 14768 KB Output is correct
65 Correct 258 ms 15296 KB Output is correct
66 Correct 270 ms 16048 KB Output is correct
67 Correct 260 ms 15028 KB Output is correct
68 Correct 129 ms 9920 KB Output is correct
69 Correct 212 ms 14808 KB Output is correct
70 Correct 162 ms 10428 KB Output is correct
71 Correct 148 ms 10696 KB Output is correct
72 Correct 197 ms 11204 KB Output is correct
73 Correct 153 ms 10284 KB Output is correct
74 Correct 147 ms 10384 KB Output is correct
75 Correct 149 ms 9404 KB Output is correct
76 Correct 148 ms 9784 KB Output is correct
77 Correct 143 ms 8864 KB Output is correct
78 Correct 153 ms 10492 KB Output is correct
79 Correct 259 ms 14768 KB Output is correct
80 Correct 173 ms 10940 KB Output is correct
81 Correct 222 ms 16192 KB Output is correct
82 Correct 254 ms 15136 KB Output is correct
83 Correct 247 ms 15808 KB Output is correct
84 Correct 258 ms 15024 KB Output is correct
85 Correct 162 ms 10672 KB Output is correct
86 Correct 150 ms 9800 KB Output is correct
87 Correct 113 ms 8124 KB Output is correct
88 Correct 267 ms 15524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 109 ms 7992 KB Output is correct
3 Correct 131 ms 8648 KB Output is correct
4 Correct 112 ms 8004 KB Output is correct
5 Correct 112 ms 9416 KB Output is correct
6 Correct 112 ms 8136 KB Output is correct
7 Correct 116 ms 8388 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 159 ms 9604 KB Output is correct
11 Correct 146 ms 10648 KB Output is correct
12 Correct 153 ms 9788 KB Output is correct
13 Correct 143 ms 9688 KB Output is correct
14 Correct 157 ms 10184 KB Output is correct
15 Correct 158 ms 9668 KB Output is correct
16 Correct 164 ms 11244 KB Output is correct
17 Correct 158 ms 10944 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 158 ms 10844 KB Output is correct
20 Correct 166 ms 10960 KB Output is correct
21 Correct 158 ms 10564 KB Output is correct
22 Correct 158 ms 10268 KB Output is correct
23 Correct 160 ms 9580 KB Output is correct
24 Correct 155 ms 10688 KB Output is correct
25 Correct 162 ms 9660 KB Output is correct
26 Correct 159 ms 9668 KB Output is correct
27 Correct 154 ms 10468 KB Output is correct
28 Correct 158 ms 9672 KB Output is correct
29 Correct 158 ms 10452 KB Output is correct
30 Correct 166 ms 9656 KB Output is correct
31 Correct 157 ms 9732 KB Output is correct
32 Correct 162 ms 10684 KB Output is correct
33 Correct 132 ms 8904 KB Output is correct
34 Correct 155 ms 11200 KB Output is correct
35 Correct 150 ms 9796 KB Output is correct
36 Correct 149 ms 9924 KB Output is correct
37 Correct 159 ms 9964 KB Output is correct
38 Correct 151 ms 9460 KB Output is correct
39 Correct 146 ms 9416 KB Output is correct
40 Correct 146 ms 10436 KB Output is correct
41 Correct 147 ms 9156 KB Output is correct
42 Correct 142 ms 9412 KB Output is correct
43 Correct 145 ms 9668 KB Output is correct
44 Correct 158 ms 10692 KB Output is correct
45 Correct 156 ms 9772 KB Output is correct
46 Correct 152 ms 9668 KB Output is correct
47 Correct 153 ms 9660 KB Output is correct
48 Correct 155 ms 10568 KB Output is correct
49 Correct 158 ms 10940 KB Output is correct
50 Correct 159 ms 9668 KB Output is correct
51 Correct 151 ms 9928 KB Output is correct
52 Correct 118 ms 8252 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 162 ms 10952 KB Output is correct
55 Correct 165 ms 9916 KB Output is correct
56 Correct 193 ms 15780 KB Output is correct
57 Correct 263 ms 16076 KB Output is correct
58 Correct 269 ms 15808 KB Output is correct
59 Correct 258 ms 16232 KB Output is correct
60 Correct 205 ms 15804 KB Output is correct
61 Correct 262 ms 15208 KB Output is correct
62 Correct 261 ms 15676 KB Output is correct
63 Correct 168 ms 9852 KB Output is correct
64 Correct 221 ms 14768 KB Output is correct
65 Correct 258 ms 15296 KB Output is correct
66 Correct 270 ms 16048 KB Output is correct
67 Correct 260 ms 15028 KB Output is correct
68 Correct 129 ms 9920 KB Output is correct
69 Correct 212 ms 14808 KB Output is correct
70 Correct 162 ms 10428 KB Output is correct
71 Correct 148 ms 10696 KB Output is correct
72 Correct 197 ms 11204 KB Output is correct
73 Correct 153 ms 10284 KB Output is correct
74 Correct 147 ms 10384 KB Output is correct
75 Correct 149 ms 9404 KB Output is correct
76 Correct 148 ms 9784 KB Output is correct
77 Correct 143 ms 8864 KB Output is correct
78 Correct 153 ms 10492 KB Output is correct
79 Correct 259 ms 14768 KB Output is correct
80 Correct 173 ms 10940 KB Output is correct
81 Correct 222 ms 16192 KB Output is correct
82 Correct 254 ms 15136 KB Output is correct
83 Correct 247 ms 15808 KB Output is correct
84 Correct 258 ms 15024 KB Output is correct
85 Correct 162 ms 10672 KB Output is correct
86 Correct 150 ms 9800 KB Output is correct
87 Correct 113 ms 8124 KB Output is correct
88 Correct 267 ms 15524 KB Output is correct
89 Correct 1 ms 2392 KB Output is correct
90 Incorrect 0 ms 2396 KB Output isn't correct
91 Halted 0 ms 0 KB -