Submission #893091

# Submission time Handle Problem Language Result Execution time Memory
893091 2023-12-26T13:42:58 Z alexander707070 Security Guard (JOI23_guard) C++14
76 / 100
4000 ms 64700 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],c,d,mins;
vector<edge> w;
unordered_set<int> tree[MAXN];
long long ans;
bool ok;
 
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];
}

void dfs(int x,int p,int maxcost,int dx,int dy){
    if(maxcost-s[x]-s[mins]>maxs){
        maxs=maxcost-s[x]-s[mins];
        c=mins; d=x; a=dx; b=dy;
    }

    for(int curr:tree[x]){
        if(curr==p)continue;
        if(s[curr]+s[x]>maxcost){
            dfs(curr,x,s[curr]+s[x],curr,x);
        }else{
            dfs(curr,x,maxcost,dx,dy);
        }
    }
}
 
int main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    cin>>n>>m>>q;

    mins=1;
    for(int i=1;i<=n;i++){
        cin>>s[i];
        ans-=s[i];
        maxs=max(maxs,s[i]);
 
        dsu[i]=i; sz[i]=1;
        if(s[i]<s[mins])mins=i;
    }
 
    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);
 
        tree[w[i].from].insert(w[i].to);
        tree[w[i].to].insert(w[i].from);
 
        ans+=s[w[i].from]+s[w[i].to];
    }
 
    ans+=maxs;
 
    cout<<ans<<"\n";
 
    for(int i=1;i<=q;i++){
 
        maxs=0;
        if(!ok)dfs(mins,0,0,0,0);
 
        if(maxs!=0){
            ans-=maxs;
            tree[a].erase(b);
            tree[b].erase(a);
 
            tree[c].insert(d);
            tree[d].insert(c);
        }else ok=true;
  
        cout<<ans<<"\n";
    }
 
 
    return 0;
}

Compilation message

guard.cpp: In function 'int main()':
guard.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for(int i=0;i<w.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12632 KB Output is correct
2 Correct 86 ms 53272 KB Output is correct
3 Correct 87 ms 54040 KB Output is correct
4 Correct 111 ms 53516 KB Output is correct
5 Correct 114 ms 53440 KB Output is correct
6 Correct 113 ms 53216 KB Output is correct
7 Correct 114 ms 53440 KB Output is correct
8 Correct 3 ms 12820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12632 KB Output is correct
2 Correct 86 ms 53272 KB Output is correct
3 Correct 87 ms 54040 KB Output is correct
4 Correct 111 ms 53516 KB Output is correct
5 Correct 114 ms 53440 KB Output is correct
6 Correct 113 ms 53216 KB Output is correct
7 Correct 114 ms 53440 KB Output is correct
8 Correct 3 ms 12820 KB Output is correct
9 Correct 3 ms 12740 KB Output is correct
10 Correct 187 ms 55572 KB Output is correct
11 Correct 96 ms 55584 KB Output is correct
12 Correct 87 ms 55252 KB Output is correct
13 Correct 85 ms 54992 KB Output is correct
14 Correct 167 ms 55132 KB Output is correct
15 Correct 170 ms 54972 KB Output is correct
16 Correct 170 ms 54972 KB Output is correct
17 Correct 171 ms 54968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12632 KB Output is correct
2 Correct 86 ms 53272 KB Output is correct
3 Correct 87 ms 54040 KB Output is correct
4 Correct 111 ms 53516 KB Output is correct
5 Correct 114 ms 53440 KB Output is correct
6 Correct 113 ms 53216 KB Output is correct
7 Correct 114 ms 53440 KB Output is correct
8 Correct 3 ms 12820 KB Output is correct
9 Correct 3 ms 12740 KB Output is correct
10 Correct 187 ms 55572 KB Output is correct
11 Correct 96 ms 55584 KB Output is correct
12 Correct 87 ms 55252 KB Output is correct
13 Correct 85 ms 54992 KB Output is correct
14 Correct 167 ms 55132 KB Output is correct
15 Correct 170 ms 54972 KB Output is correct
16 Correct 170 ms 54972 KB Output is correct
17 Correct 171 ms 54968 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 204 ms 54992 KB Output is correct
20 Correct 214 ms 55896 KB Output is correct
21 Correct 207 ms 54972 KB Output is correct
22 Correct 204 ms 55224 KB Output is correct
23 Correct 213 ms 56888 KB Output is correct
24 Correct 230 ms 56704 KB Output is correct
25 Correct 231 ms 56980 KB Output is correct
26 Correct 263 ms 57464 KB Output is correct
27 Correct 190 ms 57640 KB Output is correct
28 Correct 218 ms 56000 KB Output is correct
29 Correct 241 ms 55996 KB Output is correct
30 Correct 247 ms 56252 KB Output is correct
31 Correct 187 ms 57704 KB Output is correct
32 Correct 221 ms 55444 KB Output is correct
33 Correct 179 ms 54032 KB Output is correct
34 Correct 182 ms 55488 KB Output is correct
35 Correct 181 ms 54972 KB Output is correct
36 Correct 208 ms 57276 KB Output is correct
37 Correct 259 ms 57276 KB Output is correct
38 Correct 202 ms 55484 KB Output is correct
39 Correct 200 ms 55960 KB Output is correct
40 Correct 192 ms 56080 KB Output is correct
41 Correct 146 ms 54720 KB Output is correct
42 Correct 148 ms 54184 KB Output is correct
43 Correct 195 ms 54984 KB Output is correct
44 Correct 203 ms 54992 KB Output is correct
45 Correct 183 ms 54968 KB Output is correct
46 Correct 208 ms 55008 KB Output is correct
47 Correct 185 ms 54972 KB Output is correct
48 Correct 187 ms 55152 KB Output is correct
49 Correct 161 ms 54880 KB Output is correct
50 Correct 162 ms 54820 KB Output is correct
51 Correct 184 ms 55316 KB Output is correct
52 Correct 191 ms 54124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12632 KB Output is correct
2 Correct 86 ms 53272 KB Output is correct
3 Correct 87 ms 54040 KB Output is correct
4 Correct 111 ms 53516 KB Output is correct
5 Correct 114 ms 53440 KB Output is correct
6 Correct 113 ms 53216 KB Output is correct
7 Correct 114 ms 53440 KB Output is correct
8 Correct 3 ms 12820 KB Output is correct
9 Correct 3 ms 12740 KB Output is correct
10 Correct 187 ms 55572 KB Output is correct
11 Correct 96 ms 55584 KB Output is correct
12 Correct 87 ms 55252 KB Output is correct
13 Correct 85 ms 54992 KB Output is correct
14 Correct 167 ms 55132 KB Output is correct
15 Correct 170 ms 54972 KB Output is correct
16 Correct 170 ms 54972 KB Output is correct
17 Correct 171 ms 54968 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 204 ms 54992 KB Output is correct
20 Correct 214 ms 55896 KB Output is correct
21 Correct 207 ms 54972 KB Output is correct
22 Correct 204 ms 55224 KB Output is correct
23 Correct 213 ms 56888 KB Output is correct
24 Correct 230 ms 56704 KB Output is correct
25 Correct 231 ms 56980 KB Output is correct
26 Correct 263 ms 57464 KB Output is correct
27 Correct 190 ms 57640 KB Output is correct
28 Correct 218 ms 56000 KB Output is correct
29 Correct 241 ms 55996 KB Output is correct
30 Correct 247 ms 56252 KB Output is correct
31 Correct 187 ms 57704 KB Output is correct
32 Correct 221 ms 55444 KB Output is correct
33 Correct 179 ms 54032 KB Output is correct
34 Correct 182 ms 55488 KB Output is correct
35 Correct 181 ms 54972 KB Output is correct
36 Correct 208 ms 57276 KB Output is correct
37 Correct 259 ms 57276 KB Output is correct
38 Correct 202 ms 55484 KB Output is correct
39 Correct 200 ms 55960 KB Output is correct
40 Correct 192 ms 56080 KB Output is correct
41 Correct 146 ms 54720 KB Output is correct
42 Correct 148 ms 54184 KB Output is correct
43 Correct 195 ms 54984 KB Output is correct
44 Correct 203 ms 54992 KB Output is correct
45 Correct 183 ms 54968 KB Output is correct
46 Correct 208 ms 55008 KB Output is correct
47 Correct 185 ms 54972 KB Output is correct
48 Correct 187 ms 55152 KB Output is correct
49 Correct 161 ms 54880 KB Output is correct
50 Correct 162 ms 54820 KB Output is correct
51 Correct 184 ms 55316 KB Output is correct
52 Correct 191 ms 54124 KB Output is correct
53 Correct 3 ms 12636 KB Output is correct
54 Correct 201 ms 55084 KB Output is correct
55 Correct 204 ms 55188 KB Output is correct
56 Correct 214 ms 57840 KB Output is correct
57 Correct 244 ms 60440 KB Output is correct
58 Correct 244 ms 62704 KB Output is correct
59 Correct 280 ms 61624 KB Output is correct
60 Correct 279 ms 61136 KB Output is correct
61 Correct 305 ms 63408 KB Output is correct
62 Correct 253 ms 64000 KB Output is correct
63 Correct 254 ms 55484 KB Output is correct
64 Correct 255 ms 59572 KB Output is correct
65 Correct 282 ms 62284 KB Output is correct
66 Correct 281 ms 62352 KB Output is correct
67 Correct 298 ms 61360 KB Output is correct
68 Correct 181 ms 54712 KB Output is correct
69 Correct 200 ms 59316 KB Output is correct
70 Correct 186 ms 55484 KB Output is correct
71 Correct 197 ms 57912 KB Output is correct
72 Correct 250 ms 57280 KB Output is correct
73 Correct 194 ms 55564 KB Output is correct
74 Correct 210 ms 56448 KB Output is correct
75 Correct 203 ms 55232 KB Output is correct
76 Correct 150 ms 54464 KB Output is correct
77 Correct 147 ms 54300 KB Output is correct
78 Correct 190 ms 55504 KB Output is correct
79 Correct 251 ms 60848 KB Output is correct
80 Correct 193 ms 56248 KB Output is correct
81 Correct 221 ms 59488 KB Output is correct
82 Correct 225 ms 59932 KB Output is correct
83 Correct 237 ms 61136 KB Output is correct
84 Correct 211 ms 60356 KB Output is correct
85 Correct 162 ms 54948 KB Output is correct
86 Correct 187 ms 55488 KB Output is correct
87 Correct 182 ms 53952 KB Output is correct
88 Correct 245 ms 59832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 3 ms 12636 KB Output is correct
4 Correct 3 ms 12740 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 3 ms 12632 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 16 ms 14884 KB Output is correct
9 Correct 16 ms 14936 KB Output is correct
10 Correct 15 ms 14684 KB Output is correct
11 Correct 15 ms 14940 KB Output is correct
12 Correct 15 ms 14940 KB Output is correct
13 Correct 16 ms 14928 KB Output is correct
14 Correct 15 ms 14936 KB Output is correct
15 Correct 15 ms 14940 KB Output is correct
16 Correct 15 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 3 ms 12636 KB Output is correct
4 Correct 3 ms 12740 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 3 ms 12632 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 16 ms 14884 KB Output is correct
9 Correct 16 ms 14936 KB Output is correct
10 Correct 15 ms 14684 KB Output is correct
11 Correct 15 ms 14940 KB Output is correct
12 Correct 15 ms 14940 KB Output is correct
13 Correct 16 ms 14928 KB Output is correct
14 Correct 15 ms 14936 KB Output is correct
15 Correct 15 ms 14940 KB Output is correct
16 Correct 15 ms 14940 KB Output is correct
17 Correct 139 ms 16144 KB Output is correct
18 Correct 150 ms 16208 KB Output is correct
19 Correct 138 ms 17348 KB Output is correct
20 Correct 159 ms 19784 KB Output is correct
21 Correct 151 ms 20316 KB Output is correct
22 Correct 132 ms 19796 KB Output is correct
23 Correct 177 ms 23984 KB Output is correct
24 Correct 161 ms 20480 KB Output is correct
25 Correct 110 ms 15524 KB Output is correct
26 Correct 141 ms 18232 KB Output is correct
27 Correct 110 ms 16060 KB Output is correct
28 Correct 128 ms 15700 KB Output is correct
29 Correct 130 ms 16084 KB Output is correct
30 Correct 123 ms 15700 KB Output is correct
31 Correct 135 ms 14676 KB Output is correct
32 Correct 159 ms 14752 KB Output is correct
33 Correct 111 ms 15696 KB Output is correct
34 Correct 108 ms 15632 KB Output is correct
35 Correct 121 ms 17556 KB Output is correct
36 Correct 177 ms 25012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12632 KB Output is correct
2 Correct 86 ms 53272 KB Output is correct
3 Correct 87 ms 54040 KB Output is correct
4 Correct 111 ms 53516 KB Output is correct
5 Correct 114 ms 53440 KB Output is correct
6 Correct 113 ms 53216 KB Output is correct
7 Correct 114 ms 53440 KB Output is correct
8 Correct 3 ms 12820 KB Output is correct
9 Correct 3 ms 12740 KB Output is correct
10 Correct 187 ms 55572 KB Output is correct
11 Correct 96 ms 55584 KB Output is correct
12 Correct 87 ms 55252 KB Output is correct
13 Correct 85 ms 54992 KB Output is correct
14 Correct 167 ms 55132 KB Output is correct
15 Correct 170 ms 54972 KB Output is correct
16 Correct 170 ms 54972 KB Output is correct
17 Correct 171 ms 54968 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 204 ms 54992 KB Output is correct
20 Correct 214 ms 55896 KB Output is correct
21 Correct 207 ms 54972 KB Output is correct
22 Correct 204 ms 55224 KB Output is correct
23 Correct 213 ms 56888 KB Output is correct
24 Correct 230 ms 56704 KB Output is correct
25 Correct 231 ms 56980 KB Output is correct
26 Correct 263 ms 57464 KB Output is correct
27 Correct 190 ms 57640 KB Output is correct
28 Correct 218 ms 56000 KB Output is correct
29 Correct 241 ms 55996 KB Output is correct
30 Correct 247 ms 56252 KB Output is correct
31 Correct 187 ms 57704 KB Output is correct
32 Correct 221 ms 55444 KB Output is correct
33 Correct 179 ms 54032 KB Output is correct
34 Correct 182 ms 55488 KB Output is correct
35 Correct 181 ms 54972 KB Output is correct
36 Correct 208 ms 57276 KB Output is correct
37 Correct 259 ms 57276 KB Output is correct
38 Correct 202 ms 55484 KB Output is correct
39 Correct 200 ms 55960 KB Output is correct
40 Correct 192 ms 56080 KB Output is correct
41 Correct 146 ms 54720 KB Output is correct
42 Correct 148 ms 54184 KB Output is correct
43 Correct 195 ms 54984 KB Output is correct
44 Correct 203 ms 54992 KB Output is correct
45 Correct 183 ms 54968 KB Output is correct
46 Correct 208 ms 55008 KB Output is correct
47 Correct 185 ms 54972 KB Output is correct
48 Correct 187 ms 55152 KB Output is correct
49 Correct 161 ms 54880 KB Output is correct
50 Correct 162 ms 54820 KB Output is correct
51 Correct 184 ms 55316 KB Output is correct
52 Correct 191 ms 54124 KB Output is correct
53 Correct 3 ms 12636 KB Output is correct
54 Correct 201 ms 55084 KB Output is correct
55 Correct 204 ms 55188 KB Output is correct
56 Correct 214 ms 57840 KB Output is correct
57 Correct 244 ms 60440 KB Output is correct
58 Correct 244 ms 62704 KB Output is correct
59 Correct 280 ms 61624 KB Output is correct
60 Correct 279 ms 61136 KB Output is correct
61 Correct 305 ms 63408 KB Output is correct
62 Correct 253 ms 64000 KB Output is correct
63 Correct 254 ms 55484 KB Output is correct
64 Correct 255 ms 59572 KB Output is correct
65 Correct 282 ms 62284 KB Output is correct
66 Correct 281 ms 62352 KB Output is correct
67 Correct 298 ms 61360 KB Output is correct
68 Correct 181 ms 54712 KB Output is correct
69 Correct 200 ms 59316 KB Output is correct
70 Correct 186 ms 55484 KB Output is correct
71 Correct 197 ms 57912 KB Output is correct
72 Correct 250 ms 57280 KB Output is correct
73 Correct 194 ms 55564 KB Output is correct
74 Correct 210 ms 56448 KB Output is correct
75 Correct 203 ms 55232 KB Output is correct
76 Correct 150 ms 54464 KB Output is correct
77 Correct 147 ms 54300 KB Output is correct
78 Correct 190 ms 55504 KB Output is correct
79 Correct 251 ms 60848 KB Output is correct
80 Correct 193 ms 56248 KB Output is correct
81 Correct 221 ms 59488 KB Output is correct
82 Correct 225 ms 59932 KB Output is correct
83 Correct 237 ms 61136 KB Output is correct
84 Correct 211 ms 60356 KB Output is correct
85 Correct 162 ms 54948 KB Output is correct
86 Correct 187 ms 55488 KB Output is correct
87 Correct 182 ms 53952 KB Output is correct
88 Correct 245 ms 59832 KB Output is correct
89 Correct 3 ms 12636 KB Output is correct
90 Correct 3 ms 12636 KB Output is correct
91 Correct 3 ms 12636 KB Output is correct
92 Correct 3 ms 12740 KB Output is correct
93 Correct 3 ms 12636 KB Output is correct
94 Correct 3 ms 12632 KB Output is correct
95 Correct 3 ms 12636 KB Output is correct
96 Correct 16 ms 14884 KB Output is correct
97 Correct 16 ms 14936 KB Output is correct
98 Correct 15 ms 14684 KB Output is correct
99 Correct 15 ms 14940 KB Output is correct
100 Correct 15 ms 14940 KB Output is correct
101 Correct 16 ms 14928 KB Output is correct
102 Correct 15 ms 14936 KB Output is correct
103 Correct 15 ms 14940 KB Output is correct
104 Correct 15 ms 14940 KB Output is correct
105 Correct 139 ms 16144 KB Output is correct
106 Correct 150 ms 16208 KB Output is correct
107 Correct 138 ms 17348 KB Output is correct
108 Correct 159 ms 19784 KB Output is correct
109 Correct 151 ms 20316 KB Output is correct
110 Correct 132 ms 19796 KB Output is correct
111 Correct 177 ms 23984 KB Output is correct
112 Correct 161 ms 20480 KB Output is correct
113 Correct 110 ms 15524 KB Output is correct
114 Correct 141 ms 18232 KB Output is correct
115 Correct 110 ms 16060 KB Output is correct
116 Correct 128 ms 15700 KB Output is correct
117 Correct 130 ms 16084 KB Output is correct
118 Correct 123 ms 15700 KB Output is correct
119 Correct 135 ms 14676 KB Output is correct
120 Correct 159 ms 14752 KB Output is correct
121 Correct 111 ms 15696 KB Output is correct
122 Correct 108 ms 15632 KB Output is correct
123 Correct 121 ms 17556 KB Output is correct
124 Correct 177 ms 25012 KB Output is correct
125 Execution timed out 4035 ms 64700 KB Time limit exceeded
126 Halted 0 ms 0 KB -