Source code for submission s982

Go to diff to previous submission

fr.cpp

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <algorithm>
  4. #include <climits>
  5.  
  6. using namespace std;
  7.  
  8. int findMin(int parrent,int current, int n,int edges[1005][1005]){
  9. int minEffort = 0;
  10. bool hasOffspring = false;
  11. for(int i = 1; i < n+1; i++){
  12. if(i == parrent) continue;
  13. if(edges[current][i] > 0){
  14. minEffort += findMin(current,i,n,edges);
  15. hasOffspring = true;
  16. }
  17. }
  18. if(!hasOffspring) return edges[parrent][current];
  19. return min(minEffort,edges[parrent][current]);
  20. }
  21.  
  22. int main(){
  23. int n = 0;
  24. int c = 0;
  25. int edges[1005][1005];
  26. while(cin >> n >> c){
  27. for(int i = 0;i<=n+1;i++){
  28. for(int j=0;j<=n+1;j++){
  29. edges[i][j] = -1;
  30. }
  31. }
  32. int u,v,w;
  33. for(int i=0;i<n - 1;i++){
  34. cin >> u >> v >> w;
  35. edges[u][v] = w;
  36. edges[v][u] = w;
  37. }
  38. int minEffort = 0;
  39. for(int i = 1; i < n+1; i++){
  40. if(edges[c][i] > 0){
  41. minEffort += findMin(c,i,n,edges);
  42. }
  43. }
  44. cout << minEffort << endl;
  45.  
  46. }
  47. return 0;
  48. }
  49.  

Diff to submission s966

fr.cpp

--- c5.s966.cteam035.fr.cpp.0.fr.cpp
+++ c5.s982.cteam035.fr.cpp.0.fr.cpp
@@ -9,5 +9,5 @@
         int minEffort = 0;
         bool hasOffspring = false;
-        for(int i = 0; i < n; i++){
+        for(int i = 1; i < n+1; i++){
                 if(i == parrent) continue;
                 if(edges[current][i] > 0){