Source code for submission s912

Go to diff to previous submission

fr.cpp

  1. //
  2. // File: fr.cc
  3. // Author: cteam030
  4. //
  5. // Created on October 19, 2013, 12:07 PM
  6. //
  7.  
  8. #include <stdlib.h>
  9. #include <iostream>
  10. #include <string>
  11. #include <vector>
  12.  
  13. using namespace std;
  14.  
  15. //
  16. //
  17. //
  18.  
  19. struct Node {
  20. //int id;
  21. int child;
  22. int effort;
  23. };
  24.  
  25. int getEffort(vector<Node> nodes[], int id);
  26.  
  27. vector<bool> banned_ids;
  28.  
  29. int main(int argc, char** argv) {
  30.  
  31. size_t n, cent;
  32.  
  33. while(cin >> n >> cent) {
  34. //Node nodes[n+1];
  35. banned_ids.clear();
  36. vector<Node> nodes[n+1];
  37. for(size_t i = 1;i<n;i++) {
  38. int id,id2,eff;
  39. cin >> id >> id2 >> eff;
  40. Node n1, n2;
  41. n1.child = id2;
  42. n2.child = id;
  43. n1.effort = eff;
  44. n2.effort = eff;
  45.  
  46. nodes[id].push_back(n1);
  47. nodes[id2].push_back(n2);
  48. banned_ids.push_back(false);
  49. }
  50. banned_ids.push_back(false);
  51. banned_ids.push_back(false);
  52.  
  53.  
  54.  
  55. /////////////////////////
  56. int res = 0;
  57. /*for(size_t i=0; i<nodes[cent].subNodes.size(); i++) {
  58.   res += getEffort(nodes, nodes[cent].subNodes[i]);
  59.   }*/
  60.  
  61. for(size_t i=0; i<nodes[cent].size(); i++) {
  62. banned_ids[cent] = true;
  63. res += getEffort(nodes, nodes[cent][i].child);
  64. }
  65.  
  66. cout << res << "\n";
  67. }
  68.  
  69. return (0);
  70. }
  71.  
  72. int getEffort(vector<Node> nodes[], int id) {
  73. int effort = -1;
  74. banned_ids[id] = true;
  75. if(nodes[id].size() <= 1){
  76. return nodes[id][0].effort;
  77. }
  78. int res = 0;
  79. for(size_t i=0; i<nodes[id].size(); i++) {
  80. if(!banned_ids[nodes[id][i].child]) {
  81. res += getEffort(nodes, nodes[id][i].child);
  82. }else{
  83. effort = nodes[id][i].effort;
  84. }
  85. }
  86. //cout << res << effort
  87. if(res < effort)
  88. return res;
  89. else
  90. return effort;
  91. }
  92.  
  93.  

Diff to submission s865

fr.cpp

--- c5.s865.cteam030.fr.cpp.0.fr.cpp
+++ c5.s912.cteam030.fr.cpp.0.fr.cpp
@@ -33,4 +33,5 @@
     while(cin >> n >> cent) {
         //Node nodes[n+1];
+        banned_ids.clear();
         vector<Node> nodes[n+1];
         for(size_t i = 1;i<n;i++) {
@@ -71,5 +72,4 @@
 int getEffort(vector<Node> nodes[], int id) {
     int effort = -1;
-    bool no_child = true;
     banned_ids[id] = true;
     if(nodes[id].size() <= 1){
@@ -80,5 +80,4 @@
         if(!banned_ids[nodes[id][i].child]) {
             res += getEffort(nodes, nodes[id][i].child);
-            no_child = false;
         }else{
             effort = nodes[id][i].effort;
@@ -86,5 +85,5 @@
     }
     //cout << res << effort
-    if(res < effort && !no_child)
+    if(res < effort)
         return res;
     else