diff --git a/Appendix D/solutions/10775.cpp b/Appendix D/solutions/10775.cpp index 6c991660..e1b6c39d 100644 --- a/Appendix D/solutions/10775.cpp +++ b/Appendix D/solutions/10775.cpp @@ -1,11 +1,35 @@ -// Authored by : BaaaaaaaaaaarkingDog +// Authored by : uhwan0723 // Co-authored by : - -// http://boj.kr/**************** +// http://boj.kr/0a35dfe1f769483cb900acbd7757b1fb #include using namespace std; +const int mx = 1e5+5; +int G, P, res, par[mx]; + +int find(int x){ + if(par[x] < 0) return x; + return par[x] = find(par[x]); +} + +void uni(int x, int y){ + int u = find(x), v = find(y); + if(u == v) return; + par[u] = v; +} + int main(void){ ios::sync_with_stdio(0); cin.tie(0); - -} \ No newline at end of file + cin >> G >> P; + fill(par, par+G+5, -1); + while(P--){ + int g; + cin >> g; + int idx = find(g); + if(idx == 0) break; + uni(g, idx-1); + ++res; + } + cout << res; +}