답안 #925440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925440 2024-02-11T16:01:06 Z adhityamv 자매 도시 (APIO20_swap) C++17
100 / 100
218 ms 40900 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
const int INF=1000000000;
struct UFDS{
    int n;
    vector<vector<pii>> roots;
    vector<vector<int>> children;
    vector<int> siz;
    vector<int> unpath;
    vector<pii> pathpoints;
    UFDS(){
        n=0;
    }
    void dsinit(int nn){
        n=nn;
        for(int i=0;i<n;i++){
            vector<int> v;
            v.push_back(i);
            vector<pii> vv;
            vv.push_back(mp(i,0));
            roots.push_back(vv);
            children.push_back(v);
            siz.push_back(1);
            unpath.push_back(-1);
            pathpoints.push_back(mp(i,i));
        }
    }
    bool unite(int x,int y,int w){
        int ox=x,oy=y;
        x=roots[x].back().first;
        y=roots[y].back().first;
        if(x==y){
            if(unpath[x]==-1){
                unpath[x]=w;
                
            }
            return false;
        }
        if(siz[x]<siz[y]){
            swap(x,y);
            swap(ox,oy);
        }
        for(int i:children[y]){
            roots[i].push_back(mp(x,w));
            children[x].push_back(i);
        }
        siz[x]+=siz[y];
        if(unpath[x]==-1 && unpath[y]==-1){
            if((ox!=pathpoints[x].fi && ox!=pathpoints[x].se) || (oy!=pathpoints[y].fi && oy!=pathpoints[y].se)){
                unpath[x]=w;
            }
            else{
                pathpoints[x]=mp(pathpoints[x].fi+pathpoints[x].se-ox,pathpoints[y].fi+pathpoints[y].se-oy);
            }
        }
        if(unpath[x]==-1 && unpath[y]!=-1) unpath[x]=w;
        return true;
    }
};
UFDS ds;
bool ispath=false;
void init(int n,int m,vector<int> u,vector<int> v,vector<int> w){
    vector<pair<int,pii>> edges;
    for(int i=0;i<m;i++) edges.push_back(mp(w[i],mp(u[i],v[i])));
    sort(edges.begin(),edges.end());
    ds.dsinit(n);
    for(auto p:edges){
        ds.unite(p.se.fi,p.se.se,p.fi);
    }
    if(ds.unpath[ds.roots[0].back().fi]==-1) ispath=true;
}
int getMinimumFuelCapacity(int u,int v){
    if(ispath) return -1;
    int iu=ds.roots[u].size()-1;
    int iv=ds.roots[v].size()-1;
    while(ds.roots[u][iu].fi==ds.roots[v][iv].fi){
        iu--,iv--;
    }
    iu++,iv++;
    while(ds.unpath[ds.roots[u][iu].fi]==-1) iu++;
    return max(max(ds.roots[u][iu].se,ds.roots[v][iv].se),ds.unpath[ds.roots[u][iu].fi]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 76 ms 23600 KB Output is correct
10 Correct 109 ms 27988 KB Output is correct
11 Correct 134 ms 27552 KB Output is correct
12 Correct 141 ms 28972 KB Output is correct
13 Correct 67 ms 21440 KB Output is correct
14 Correct 83 ms 24264 KB Output is correct
15 Correct 148 ms 32368 KB Output is correct
16 Correct 171 ms 31656 KB Output is correct
17 Correct 152 ms 32956 KB Output is correct
18 Correct 119 ms 25568 KB Output is correct
19 Correct 51 ms 9680 KB Output is correct
20 Correct 150 ms 32612 KB Output is correct
21 Correct 150 ms 32016 KB Output is correct
22 Correct 218 ms 33472 KB Output is correct
23 Correct 120 ms 26188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 98 ms 22588 KB Output is correct
4 Correct 101 ms 22676 KB Output is correct
5 Correct 101 ms 22764 KB Output is correct
6 Correct 104 ms 22672 KB Output is correct
7 Correct 104 ms 22836 KB Output is correct
8 Correct 119 ms 22588 KB Output is correct
9 Correct 101 ms 22816 KB Output is correct
10 Correct 107 ms 22340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 448 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 484 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 76 ms 23600 KB Output is correct
11 Correct 109 ms 27988 KB Output is correct
12 Correct 134 ms 27552 KB Output is correct
13 Correct 141 ms 28972 KB Output is correct
14 Correct 67 ms 21440 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 448 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 484 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 10 ms 3732 KB Output is correct
35 Correct 141 ms 28640 KB Output is correct
36 Correct 119 ms 28268 KB Output is correct
37 Correct 103 ms 28056 KB Output is correct
38 Correct 94 ms 27580 KB Output is correct
39 Correct 129 ms 26816 KB Output is correct
40 Correct 97 ms 24636 KB Output is correct
41 Correct 108 ms 29248 KB Output is correct
42 Correct 107 ms 29368 KB Output is correct
43 Correct 64 ms 20956 KB Output is correct
44 Correct 128 ms 26788 KB Output is correct
45 Correct 79 ms 23492 KB Output is correct
46 Correct 102 ms 28076 KB Output is correct
47 Correct 90 ms 25536 KB Output is correct
48 Correct 76 ms 22044 KB Output is correct
49 Correct 50 ms 10956 KB Output is correct
50 Correct 41 ms 8136 KB Output is correct
51 Correct 69 ms 17784 KB Output is correct
52 Correct 143 ms 32656 KB Output is correct
53 Correct 107 ms 28352 KB Output is correct
54 Correct 139 ms 35256 KB Output is correct
55 Correct 61 ms 21180 KB Output is correct
56 Correct 117 ms 27448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 76 ms 23600 KB Output is correct
10 Correct 109 ms 27988 KB Output is correct
11 Correct 134 ms 27552 KB Output is correct
12 Correct 141 ms 28972 KB Output is correct
13 Correct 67 ms 21440 KB Output is correct
14 Correct 83 ms 24264 KB Output is correct
15 Correct 148 ms 32368 KB Output is correct
16 Correct 171 ms 31656 KB Output is correct
17 Correct 152 ms 32956 KB Output is correct
18 Correct 119 ms 25568 KB Output is correct
19 Correct 98 ms 22588 KB Output is correct
20 Correct 101 ms 22676 KB Output is correct
21 Correct 101 ms 22764 KB Output is correct
22 Correct 104 ms 22672 KB Output is correct
23 Correct 104 ms 22836 KB Output is correct
24 Correct 119 ms 22588 KB Output is correct
25 Correct 101 ms 22816 KB Output is correct
26 Correct 107 ms 22340 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 448 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 448 KB Output is correct
36 Correct 10 ms 3732 KB Output is correct
37 Correct 141 ms 28640 KB Output is correct
38 Correct 119 ms 28268 KB Output is correct
39 Correct 103 ms 28056 KB Output is correct
40 Correct 94 ms 27580 KB Output is correct
41 Correct 129 ms 26816 KB Output is correct
42 Correct 97 ms 24636 KB Output is correct
43 Correct 108 ms 29248 KB Output is correct
44 Correct 107 ms 29368 KB Output is correct
45 Correct 64 ms 20956 KB Output is correct
46 Correct 128 ms 26788 KB Output is correct
47 Correct 15 ms 3988 KB Output is correct
48 Correct 162 ms 32368 KB Output is correct
49 Correct 154 ms 32444 KB Output is correct
50 Correct 176 ms 31912 KB Output is correct
51 Correct 160 ms 31224 KB Output is correct
52 Correct 167 ms 28952 KB Output is correct
53 Correct 105 ms 23940 KB Output is correct
54 Correct 159 ms 33428 KB Output is correct
55 Correct 161 ms 32960 KB Output is correct
56 Correct 121 ms 25276 KB Output is correct
57 Correct 140 ms 30452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 76 ms 23600 KB Output is correct
11 Correct 109 ms 27988 KB Output is correct
12 Correct 134 ms 27552 KB Output is correct
13 Correct 141 ms 28972 KB Output is correct
14 Correct 67 ms 21440 KB Output is correct
15 Correct 83 ms 24264 KB Output is correct
16 Correct 148 ms 32368 KB Output is correct
17 Correct 171 ms 31656 KB Output is correct
18 Correct 152 ms 32956 KB Output is correct
19 Correct 119 ms 25568 KB Output is correct
20 Correct 98 ms 22588 KB Output is correct
21 Correct 101 ms 22676 KB Output is correct
22 Correct 101 ms 22764 KB Output is correct
23 Correct 104 ms 22672 KB Output is correct
24 Correct 104 ms 22836 KB Output is correct
25 Correct 119 ms 22588 KB Output is correct
26 Correct 101 ms 22816 KB Output is correct
27 Correct 107 ms 22340 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 448 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 448 KB Output is correct
37 Correct 10 ms 3732 KB Output is correct
38 Correct 141 ms 28640 KB Output is correct
39 Correct 119 ms 28268 KB Output is correct
40 Correct 103 ms 28056 KB Output is correct
41 Correct 94 ms 27580 KB Output is correct
42 Correct 129 ms 26816 KB Output is correct
43 Correct 97 ms 24636 KB Output is correct
44 Correct 108 ms 29248 KB Output is correct
45 Correct 107 ms 29368 KB Output is correct
46 Correct 64 ms 20956 KB Output is correct
47 Correct 128 ms 26788 KB Output is correct
48 Correct 15 ms 3988 KB Output is correct
49 Correct 162 ms 32368 KB Output is correct
50 Correct 154 ms 32444 KB Output is correct
51 Correct 176 ms 31912 KB Output is correct
52 Correct 160 ms 31224 KB Output is correct
53 Correct 167 ms 28952 KB Output is correct
54 Correct 105 ms 23940 KB Output is correct
55 Correct 159 ms 33428 KB Output is correct
56 Correct 161 ms 32960 KB Output is correct
57 Correct 121 ms 25276 KB Output is correct
58 Correct 140 ms 30452 KB Output is correct
59 Correct 51 ms 9680 KB Output is correct
60 Correct 150 ms 32612 KB Output is correct
61 Correct 150 ms 32016 KB Output is correct
62 Correct 218 ms 33472 KB Output is correct
63 Correct 120 ms 26188 KB Output is correct
64 Correct 2 ms 604 KB Output is correct
65 Correct 1 ms 604 KB Output is correct
66 Correct 2 ms 604 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 604 KB Output is correct
69 Correct 1 ms 484 KB Output is correct
70 Correct 1 ms 604 KB Output is correct
71 Correct 1 ms 604 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 79 ms 23492 KB Output is correct
75 Correct 102 ms 28076 KB Output is correct
76 Correct 90 ms 25536 KB Output is correct
77 Correct 76 ms 22044 KB Output is correct
78 Correct 50 ms 10956 KB Output is correct
79 Correct 41 ms 8136 KB Output is correct
80 Correct 69 ms 17784 KB Output is correct
81 Correct 143 ms 32656 KB Output is correct
82 Correct 107 ms 28352 KB Output is correct
83 Correct 139 ms 35256 KB Output is correct
84 Correct 61 ms 21180 KB Output is correct
85 Correct 117 ms 27448 KB Output is correct
86 Correct 41 ms 9052 KB Output is correct
87 Correct 159 ms 31932 KB Output is correct
88 Correct 195 ms 31416 KB Output is correct
89 Correct 124 ms 25072 KB Output is correct
90 Correct 107 ms 13692 KB Output is correct
91 Correct 120 ms 14020 KB Output is correct
92 Correct 110 ms 21340 KB Output is correct
93 Correct 207 ms 34980 KB Output is correct
94 Correct 175 ms 32776 KB Output is correct
95 Correct 202 ms 40900 KB Output is correct
96 Correct 129 ms 25412 KB Output is correct
97 Correct 139 ms 29132 KB Output is correct