]> Skullheadx's Git Forge - CCC.git/commitdiff
2016 S3 attempt not work
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Sat, 19 Nov 2022 23:22:06 +0000 (18:22 -0500)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Sat, 19 Nov 2022 23:22:06 +0000 (18:22 -0500)
Main/C++/2016/S3.cpp
Main/Python/2016/S3.py

index 45cf60792e7822a18429a7121734ff4ab338e205..199721643291bb6ea79e5f5e602d86daf57701c0 100644 (file)
@@ -37,40 +37,41 @@ int main()
             tree[b].push_back(a);
         }
     }
-    queue<vector<vector<int>>> q;
+    queue<vector<int>> q;
     for (int i = 0; i < M; i++)
     {
-        q.push({{pho_restaurants[i],0},{}});
+        q.push({pho_restaurants[i],0,0});
     }
-    set<vector<vector<int>>> seen;
-    vector<int> pho_seen;
-    vector<vector<int>> temp, temp2;
+    set<vector<int>> seen;
+    vector<int> temp;
     int current, length;
+    long long pho_seen, complete = (pow(10,pho_restaurants.size()) - 1)/9;
     while (!q.empty())
     {
-        temp = q.front();
-
-        current = temp[0][0];
-        length = temp[0][1];
-        pho_seen = temp[1];
+        current=q.front()[0], length=q.front()[1], pho_seen = q.front()[2];
         q.pop();
-        temp2 = {{current},pho_seen};
-
-        if (find(seen.begin(),seen.end(),temp2) != seen.end())
+        temp = {current, pho_seen};
+        if (find(seen.begin(),seen.end(),temp) != seen.end())
         {
             continue;
         }
         else
         {
-            seen.insert(temp2);
+            seen.insert(temp);
         }
 
 
-        if (find(pho_restaurants.begin(),pho_restaurants.end(),current)!= pho_restaurants.end() && find(pho_seen.begin(),pho_seen.end(),current)== pho_seen.end())
+        if (find(pho_restaurants.begin(),pho_restaurants.end(),current)!= pho_restaurants.end())
         {
-            pho_seen.push_back(current);
+            long num = pow(10,(find(pho_restaurants.begin(), pho_restaurants.end(),current)-pho_restaurants.begin()));
+            if ((pho_seen / num)% 10 == 0)
+            {
+                pho_seen += num;
+
+            }
         }
-        if (pho_seen.size() == pho_restaurants.size())
+        cout << current << "|" << length << "|" << pho_seen << endl;
+        if (pho_seen == complete)
         {
             cout << length;
             return 0;
@@ -78,7 +79,7 @@ int main()
 
         for (int r = 0; r < tree[current].size();r++)
         {
-            q.push({{tree[current][r], length + 1}, pho_seen});
+            q.push({tree[current][r], length + 1, pho_seen});
         }
     }
     return 0;
index eeea9859eef71590e710540cebc9fec80d4a5e16..08c10b2451f1853a48b07aafc796e9700da6cdce 100644 (file)
@@ -16,19 +16,22 @@ for i in range(N-1):
 
 q = Queue()
 for i in pho_restaurants:
-    q.put((i,0, set()))
+    q.put((i, 0, 0))
 seen = set()
+
+complete = (10 ** len(pho_restaurants) - 1)/9
 while not q.empty():
     current, length, pho_seen = q.get()
-    if (current, tuple(pho_seen)) in seen:
+    if (current, pho_seen) in seen:
         continue
     else:
-        seen.add((current,tuple(pho_seen)))
+        seen.add((current,pho_seen))
     if current in pho_restaurants:
-        pho_seen.add(current)
-    if len(pho_seen) == len(pho_restaurants):
+        if (pho_seen // (10 ** pho_restaurants.index(current))) % 10 == 0:
+            pho_seen += 10 ** pho_restaurants.index(current)
+    if pho_seen == complete:
         print(length)
         break
 
     for r in tree[current]:
-        q.put((r, length + 1, pho_seen.copy()))
+        q.put((r, length + 1, pho_seen))