From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Sat, 19 Nov 2022 22:33:17 +0000 (-0500) Subject: 2016 S3 wip X-Git-Url: http://git.skullheadx.com/nixos/static/tech/openbsd_html_css/post.html?a=commitdiff_plain;h=c5922d43a1b71c553cbc83928b100dcbcf3f286c;p=CCC.git 2016 S3 wip --- diff --git a/Main/C++/2016/S3.cpp b/Main/C++/2016/S3.cpp index eb48f75..45cf607 100644 --- a/Main/C++/2016/S3.cpp +++ b/Main/C++/2016/S3.cpp @@ -16,15 +16,13 @@ int main() map> tree; int a,b; - vector temp1{0}; for (int i = 0; i < N-1;i++) { cin >> a >> b; if ((tree.find(a) == tree.end())) { // not found - temp1[0] = b; - tree.insert({a,temp1}); + tree.insert({a,{b}}); } else {// found @@ -32,8 +30,7 @@ int main() } if ((tree.find(b) == tree.end())) { // not found - temp1[0]= a; - tree.insert({b,temp1}); + tree.insert({b,{a}}); } else {// found @@ -43,13 +40,10 @@ int main() queue>> q; for (int i = 0; i < M; i++) { - vector tseen; - vector c{pho_restaurants[i],0}; - vector> temp{c,tseen}; - q.push(temp); + q.push({{pho_restaurants[i],0},{}}); } - vector>> seen; - vector pho_seen,temp3; + set>> seen; + vector pho_seen; vector> temp, temp2; int current, length; while (!q.empty()) @@ -60,18 +54,15 @@ int main() length = temp[0][1]; pho_seen = temp[1]; q.pop(); - temp3.clear(); - temp3.push_back(current); - temp2.clear(); - temp2.push_back(temp3); - temp2.push_back(pho_seen); + temp2 = {{current},pho_seen}; + if (find(seen.begin(),seen.end(),temp2) != seen.end()) { continue; } else { - seen.push_back(temp2); + seen.insert(temp2); } @@ -87,9 +78,7 @@ int main() for (int r = 0; r < tree[current].size();r++) { - vector c{tree[current][r], length + 1}; - vector> next_value{c,pho_seen}; - q.push(next_value); + q.push({{tree[current][r], length + 1}, pho_seen}); } } return 0; diff --git a/Main/C++/test.cpp b/Main/C++/test.cpp index 1a874e2..97b9476 100644 --- a/Main/C++/test.cpp +++ b/Main/C++/test.cpp @@ -12,13 +12,16 @@ void print_v(vector v) int main() { - vector v{1,2,3}; - vector v2 = v; - print_v(v); - print_v(v2); - v2[1] = 4; - print_v(v); - print_v(v2); +// vector v{1,2,3}; +// vector v2 = v; +// print_v(v); +// print_v(v2); +// v2[1] = 4; +// print_v(v); +// print_v(v2); + + +//vector,vector> v; return 0; }