Submission #1048104

# Submission time Handle Problem Language Result Execution time Memory
1048104 2024-08-07T22:38:49 Z vjudge1 Fountain Parks (IOI21_parks) C++17
55 / 100
1551 ms 124452 KB
#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
mt19937 rng;
struct bpmatch{
    vector<int>adj[200100];
    int match1[200100],match2[400100],dep[200100];
    void AE(int a,int b){
        adj[a].push_back(b);
    }
    int bfs(int n){
        queue<int>q;
        for(int i=1;i<=n;i++)
            if(!match1[i])
                q.push(i),
                dep[i]=1;
            else dep[i]=0;
        dep[0]=0;
        while(q.size()){
            int x=q.front();
            q.pop();
            if(dep[x]>=dep[0]&&dep[0])
                continue;
            for(auto i:adj[x])
                if(!dep[match2[i]])
                    dep[match2[i]]=dep[x]+1,
                    q.push(match2[i]);
        }
        return dep[0];
    }
    int dfs(int n){
        if(!n)return 1;
        for(auto i:adj[n]){
            if(dep[match2[i]]==dep[n]+1&&dfs(match2[i]))
                return match2[match1[n]=i]=n,1;
        }
        dep[n]=1e9;
        return 0;
    }
    int matching(int n){
        int ans=0;
        while(bfs(n))for(int i=1;i<=n;i++)
            if(!match1[i]) ans+=dfs(i);
        return ans;
    }
} G;
map<int,int> pts[200100];
vector<pair<int,int>> tre_edges;
struct dsu{
    int par[200100];
    int abp(int n){
        return par[n]?par[n]=abp(par[n]):n;
    }
    int  merge(int a,int b){
        a=abp(a),b=abp(b);
        return a-b?par[a]=b:0;
    }
} DT;
int Xpos[400100],Ypos[400100];
int construct_roads(std::vector<int> x, std::vector<int> y) {
    int n=x.size();
    for(int i=0;i<n;i++)
        pts[x[i]][y[i]]=i+1;
    vector<tuple<int,int,int>>E;
    for(int i=0;i<n;i++) {
        if(pts[x[i]+2][y[i]])
            E.push_back({i+1,pts[x[i]+2][y[i]],0});
        if(pts[x[i]][y[i]+2])
            E.push_back({i+1,pts[x[i]][y[i]+2],1});
    }
    vector<int>u,v,A,B;
    shuffle(E.begin(),E.end(),rng);
    int CC=0;
    for(auto [i,j,k]:E){
        if(DT.merge(i,j)){
            u.push_back(i-1);
            v.push_back(j-1);
            int x1=x[i-1]+1,y1=y[i-1]+1;
            int x2=x1,y2=y1;
            if(k)x2-=2;
            else y2-=2;
            if(!pts[x1][y1])
                pts[x1][y1]=++CC,
                Xpos[CC]=x1,
                Ypos[CC]=y1;
            if(!pts[x2][y2])
                pts[x2][y2]=++CC,
                Xpos[CC]=x2,
                Ypos[CC]=y2;
            G.AE(u.size(),pts[x1][y1]);
            G.AE(u.size(),pts[x2][y2]);
        }
    }
    if(u.size()-n+1)return 0;
    assert(G.matching(n-1)==n-1);
    for(int i=1;i<n;i++)
        A.push_back(Xpos[G.match1[i]]),
        B.push_back(Ypos[G.match1[i]]);
    build(u,v,A,B);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18780 KB Output is correct
2 Correct 2 ms 20936 KB Output is correct
3 Correct 2 ms 16732 KB Output is correct
4 Correct 2 ms 20828 KB Output is correct
5 Correct 2 ms 20876 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 2 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 188 ms 51088 KB Output is correct
10 Correct 13 ms 24032 KB Output is correct
11 Correct 70 ms 37096 KB Output is correct
12 Correct 19 ms 25512 KB Output is correct
13 Correct 51 ms 30216 KB Output is correct
14 Correct 3 ms 19032 KB Output is correct
15 Correct 4 ms 19292 KB Output is correct
16 Correct 182 ms 50900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18780 KB Output is correct
2 Correct 2 ms 20936 KB Output is correct
3 Correct 2 ms 16732 KB Output is correct
4 Correct 2 ms 20828 KB Output is correct
5 Correct 2 ms 20876 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 2 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 188 ms 51088 KB Output is correct
10 Correct 13 ms 24032 KB Output is correct
11 Correct 70 ms 37096 KB Output is correct
12 Correct 19 ms 25512 KB Output is correct
13 Correct 51 ms 30216 KB Output is correct
14 Correct 3 ms 19032 KB Output is correct
15 Correct 4 ms 19292 KB Output is correct
16 Correct 182 ms 50900 KB Output is correct
17 Correct 3 ms 20824 KB Output is correct
18 Correct 2 ms 20828 KB Output is correct
19 Correct 2 ms 20828 KB Output is correct
20 Correct 2 ms 20828 KB Output is correct
21 Correct 2 ms 18780 KB Output is correct
22 Correct 3 ms 20824 KB Output is correct
23 Correct 441 ms 72964 KB Output is correct
24 Correct 3 ms 20828 KB Output is correct
25 Correct 3 ms 21084 KB Output is correct
26 Correct 5 ms 19548 KB Output is correct
27 Correct 6 ms 19548 KB Output is correct
28 Correct 137 ms 40928 KB Output is correct
29 Correct 219 ms 51392 KB Output is correct
30 Correct 323 ms 60928 KB Output is correct
31 Correct 418 ms 71848 KB Output is correct
32 Correct 2 ms 20828 KB Output is correct
33 Correct 2 ms 20956 KB Output is correct
34 Correct 2 ms 20828 KB Output is correct
35 Correct 3 ms 16732 KB Output is correct
36 Correct 2 ms 16732 KB Output is correct
37 Correct 2 ms 20828 KB Output is correct
38 Correct 2 ms 20828 KB Output is correct
39 Correct 2 ms 20828 KB Output is correct
40 Correct 3 ms 20828 KB Output is correct
41 Correct 3 ms 16732 KB Output is correct
42 Correct 3 ms 20824 KB Output is correct
43 Correct 4 ms 19288 KB Output is correct
44 Correct 5 ms 19548 KB Output is correct
45 Correct 187 ms 48196 KB Output is correct
46 Correct 293 ms 60808 KB Output is correct
47 Correct 334 ms 60928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18780 KB Output is correct
2 Correct 2 ms 20936 KB Output is correct
3 Correct 2 ms 16732 KB Output is correct
4 Correct 2 ms 20828 KB Output is correct
5 Correct 2 ms 20876 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 2 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 188 ms 51088 KB Output is correct
10 Correct 13 ms 24032 KB Output is correct
11 Correct 70 ms 37096 KB Output is correct
12 Correct 19 ms 25512 KB Output is correct
13 Correct 51 ms 30216 KB Output is correct
14 Correct 3 ms 19032 KB Output is correct
15 Correct 4 ms 19292 KB Output is correct
16 Correct 182 ms 50900 KB Output is correct
17 Correct 3 ms 20824 KB Output is correct
18 Correct 2 ms 20828 KB Output is correct
19 Correct 2 ms 20828 KB Output is correct
20 Correct 2 ms 20828 KB Output is correct
21 Correct 2 ms 18780 KB Output is correct
22 Correct 3 ms 20824 KB Output is correct
23 Correct 441 ms 72964 KB Output is correct
24 Correct 3 ms 20828 KB Output is correct
25 Correct 3 ms 21084 KB Output is correct
26 Correct 5 ms 19548 KB Output is correct
27 Correct 6 ms 19548 KB Output is correct
28 Correct 137 ms 40928 KB Output is correct
29 Correct 219 ms 51392 KB Output is correct
30 Correct 323 ms 60928 KB Output is correct
31 Correct 418 ms 71848 KB Output is correct
32 Correct 2 ms 20828 KB Output is correct
33 Correct 2 ms 20956 KB Output is correct
34 Correct 2 ms 20828 KB Output is correct
35 Correct 3 ms 16732 KB Output is correct
36 Correct 2 ms 16732 KB Output is correct
37 Correct 2 ms 20828 KB Output is correct
38 Correct 2 ms 20828 KB Output is correct
39 Correct 2 ms 20828 KB Output is correct
40 Correct 3 ms 20828 KB Output is correct
41 Correct 3 ms 16732 KB Output is correct
42 Correct 3 ms 20824 KB Output is correct
43 Correct 4 ms 19288 KB Output is correct
44 Correct 5 ms 19548 KB Output is correct
45 Correct 187 ms 48196 KB Output is correct
46 Correct 293 ms 60808 KB Output is correct
47 Correct 334 ms 60928 KB Output is correct
48 Correct 2 ms 20828 KB Output is correct
49 Correct 2 ms 20828 KB Output is correct
50 Correct 2 ms 20928 KB Output is correct
51 Correct 2 ms 20920 KB Output is correct
52 Correct 2 ms 20936 KB Output is correct
53 Correct 2 ms 20828 KB Output is correct
54 Correct 2 ms 20828 KB Output is correct
55 Runtime error 406 ms 124452 KB Execution killed with signal 6
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18780 KB Output is correct
2 Correct 2 ms 20936 KB Output is correct
3 Correct 2 ms 16732 KB Output is correct
4 Correct 2 ms 20828 KB Output is correct
5 Correct 2 ms 20876 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 2 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 188 ms 51088 KB Output is correct
10 Correct 13 ms 24032 KB Output is correct
11 Correct 70 ms 37096 KB Output is correct
12 Correct 19 ms 25512 KB Output is correct
13 Correct 51 ms 30216 KB Output is correct
14 Correct 3 ms 19032 KB Output is correct
15 Correct 4 ms 19292 KB Output is correct
16 Correct 182 ms 50900 KB Output is correct
17 Correct 2 ms 20824 KB Output is correct
18 Correct 2 ms 20828 KB Output is correct
19 Correct 2 ms 18780 KB Output is correct
20 Correct 1551 ms 69368 KB Output is correct
21 Correct 188 ms 73664 KB Output is correct
22 Correct 1546 ms 69712 KB Output is correct
23 Correct 232 ms 73592 KB Output is correct
24 Correct 193 ms 49652 KB Output is correct
25 Correct 310 ms 71344 KB Output is correct
26 Correct 296 ms 71860 KB Output is correct
27 Correct 340 ms 82608 KB Output is correct
28 Correct 347 ms 82608 KB Output is correct
29 Correct 359 ms 82604 KB Output is correct
30 Correct 342 ms 82604 KB Output is correct
31 Correct 3 ms 20828 KB Output is correct
32 Correct 16 ms 24920 KB Output is correct
33 Correct 32 ms 33636 KB Output is correct
34 Correct 181 ms 75216 KB Output is correct
35 Correct 10 ms 21084 KB Output is correct
36 Correct 48 ms 29616 KB Output is correct
37 Correct 113 ms 40200 KB Output is correct
38 Correct 112 ms 41820 KB Output is correct
39 Correct 156 ms 49808 KB Output is correct
40 Correct 214 ms 57924 KB Output is correct
41 Correct 269 ms 65272 KB Output is correct
42 Correct 324 ms 74000 KB Output is correct
43 Correct 3 ms 20824 KB Output is correct
44 Correct 3 ms 20824 KB Output is correct
45 Correct 2 ms 20828 KB Output is correct
46 Correct 2 ms 16728 KB Output is correct
47 Correct 2 ms 16732 KB Output is correct
48 Correct 2 ms 20828 KB Output is correct
49 Correct 2 ms 20828 KB Output is correct
50 Correct 2 ms 20828 KB Output is correct
51 Correct 2 ms 20828 KB Output is correct
52 Correct 2 ms 16732 KB Output is correct
53 Correct 2 ms 20964 KB Output is correct
54 Correct 4 ms 19292 KB Output is correct
55 Correct 6 ms 19388 KB Output is correct
56 Correct 180 ms 48256 KB Output is correct
57 Correct 290 ms 60672 KB Output is correct
58 Correct 294 ms 60636 KB Output is correct
59 Correct 2 ms 16988 KB Output is correct
60 Correct 3 ms 20940 KB Output is correct
61 Correct 2 ms 16848 KB Output is correct
62 Correct 429 ms 82864 KB Output is correct
63 Correct 432 ms 82892 KB Output is correct
64 Correct 419 ms 82604 KB Output is correct
65 Correct 7 ms 19804 KB Output is correct
66 Correct 10 ms 20572 KB Output is correct
67 Correct 187 ms 47660 KB Output is correct
68 Correct 286 ms 61188 KB Output is correct
69 Correct 424 ms 74672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18780 KB Output is correct
2 Correct 2 ms 20936 KB Output is correct
3 Correct 2 ms 16732 KB Output is correct
4 Correct 2 ms 20828 KB Output is correct
5 Correct 2 ms 20876 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 2 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 188 ms 51088 KB Output is correct
10 Correct 13 ms 24032 KB Output is correct
11 Correct 70 ms 37096 KB Output is correct
12 Correct 19 ms 25512 KB Output is correct
13 Correct 51 ms 30216 KB Output is correct
14 Correct 3 ms 19032 KB Output is correct
15 Correct 4 ms 19292 KB Output is correct
16 Correct 182 ms 50900 KB Output is correct
17 Correct 319 ms 81644 KB Output is correct
18 Correct 311 ms 81580 KB Output is correct
19 Correct 698 ms 76112 KB Output is correct
20 Correct 302 ms 69024 KB Output is correct
21 Correct 289 ms 70660 KB Output is correct
22 Correct 2 ms 20824 KB Output is correct
23 Correct 37 ms 29360 KB Output is correct
24 Correct 20 ms 23188 KB Output is correct
25 Correct 69 ms 33932 KB Output is correct
26 Correct 145 ms 44024 KB Output is correct
27 Correct 136 ms 46716 KB Output is correct
28 Correct 185 ms 53452 KB Output is correct
29 Correct 228 ms 59916 KB Output is correct
30 Correct 283 ms 66152 KB Output is correct
31 Correct 334 ms 73140 KB Output is correct
32 Correct 430 ms 74496 KB Output is correct
33 Correct 434 ms 82760 KB Output is correct
34 Correct 7 ms 19804 KB Output is correct
35 Correct 12 ms 20828 KB Output is correct
36 Correct 180 ms 47332 KB Output is correct
37 Correct 283 ms 60928 KB Output is correct
38 Correct 410 ms 74164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18780 KB Output is correct
2 Correct 2 ms 20936 KB Output is correct
3 Correct 2 ms 16732 KB Output is correct
4 Correct 2 ms 20828 KB Output is correct
5 Correct 2 ms 20876 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 2 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 188 ms 51088 KB Output is correct
10 Correct 13 ms 24032 KB Output is correct
11 Correct 70 ms 37096 KB Output is correct
12 Correct 19 ms 25512 KB Output is correct
13 Correct 51 ms 30216 KB Output is correct
14 Correct 3 ms 19032 KB Output is correct
15 Correct 4 ms 19292 KB Output is correct
16 Correct 182 ms 50900 KB Output is correct
17 Correct 3 ms 20824 KB Output is correct
18 Correct 2 ms 20828 KB Output is correct
19 Correct 2 ms 20828 KB Output is correct
20 Correct 2 ms 20828 KB Output is correct
21 Correct 2 ms 18780 KB Output is correct
22 Correct 3 ms 20824 KB Output is correct
23 Correct 441 ms 72964 KB Output is correct
24 Correct 3 ms 20828 KB Output is correct
25 Correct 3 ms 21084 KB Output is correct
26 Correct 5 ms 19548 KB Output is correct
27 Correct 6 ms 19548 KB Output is correct
28 Correct 137 ms 40928 KB Output is correct
29 Correct 219 ms 51392 KB Output is correct
30 Correct 323 ms 60928 KB Output is correct
31 Correct 418 ms 71848 KB Output is correct
32 Correct 2 ms 20828 KB Output is correct
33 Correct 2 ms 20956 KB Output is correct
34 Correct 2 ms 20828 KB Output is correct
35 Correct 3 ms 16732 KB Output is correct
36 Correct 2 ms 16732 KB Output is correct
37 Correct 2 ms 20828 KB Output is correct
38 Correct 2 ms 20828 KB Output is correct
39 Correct 2 ms 20828 KB Output is correct
40 Correct 3 ms 20828 KB Output is correct
41 Correct 3 ms 16732 KB Output is correct
42 Correct 3 ms 20824 KB Output is correct
43 Correct 4 ms 19288 KB Output is correct
44 Correct 5 ms 19548 KB Output is correct
45 Correct 187 ms 48196 KB Output is correct
46 Correct 293 ms 60808 KB Output is correct
47 Correct 334 ms 60928 KB Output is correct
48 Correct 2 ms 20828 KB Output is correct
49 Correct 2 ms 20828 KB Output is correct
50 Correct 2 ms 20928 KB Output is correct
51 Correct 2 ms 20920 KB Output is correct
52 Correct 2 ms 20936 KB Output is correct
53 Correct 2 ms 20828 KB Output is correct
54 Correct 2 ms 20828 KB Output is correct
55 Runtime error 406 ms 124452 KB Execution killed with signal 6
56 Halted 0 ms 0 KB -