Source code for submission s1078

Go to diff to previous submission

otherBunny.cpp

  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. struct Point{
  6. int m_counter;
  7. vector<short> m_points;
  8. Point(){
  9. m_counter = 0;
  10. }
  11. };
  12.  
  13. int main(void){
  14. int points, lines;
  15. while(cin >> points >> lines){
  16. Point ** p_points = new Point* [points];
  17. for(int i = 0; i < points ; i++){
  18. p_points[i] = NULL;
  19. }
  20.  
  21. short first, second;
  22. for(int i = 0; i < lines ; i++){
  23. cin >> first >> second;
  24. first--;
  25. second--;
  26. if(p_points[first]){
  27. p_points[first]->m_counter++;
  28. p_points[first]->m_points.push_back(second);
  29. }
  30. else{
  31. p_points[first] = new Point();
  32. p_points[first]->m_counter = 1;
  33. p_points[first]->m_points.push_back(second);
  34. }
  35.  
  36. if(p_points[second]){
  37. p_points[second]->m_counter++;
  38. p_points[second]->m_points.push_back(first);
  39. }
  40. else{
  41. p_points[second] = new Point();
  42. p_points[second]->m_counter = 1;
  43. p_points[second]->m_points.push_back(first);
  44. }
  45. }
  46.  
  47. bool isBunny = false;
  48.  
  49. for(int i = 0; i < points ; i++){
  50. if(p_points[i] && p_points[i]->m_counter==4){
  51. bool found = true;
  52. for(int j = 0; j < p_points[i]->m_points.size(); j++){
  53. if(p_points[ p_points[i]->m_points[j] ]->m_counter != 1){
  54. found = false;
  55. break;
  56. }
  57. }
  58. if(found) {
  59. cout << "YES" << endl;
  60. goto konec;
  61. }
  62. }
  63. }
  64. cout << "NO" << endl;
  65. konec:
  66. ;
  67. }
  68. return 0;
  69. }
  70.  
  71.  

Diff to submission s913

fn.cpp

--- c5.s913.cteam009.fn.cpp.0.fn.cpp
+++ c5.s1078.cteam009.fn.cpp.0.otherBunny.cpp
@@ -1,68 +1,69 @@
-#include<iostream>
-#include<vector>
+#include <iostream>
+#include <vector>
 using namespace std;
 
-struct Point {
-        unsigned counter;
-        vector<short> points;
-
-        Point() {
-                counter = 0;
+struct Point{
+        int m_counter;
+        vector<short> m_points;
+        Point(){
+                m_counter = 0;
         }
 };
 
-Point ** graph;
-unsigned N;
-
-inline bool isPaw(unsigned point) {
-        return (graph[point]->counter == 1);
-}
-
-bool isBunny(unsigned point) {
-        for(vector<short>::iterator it = graph[point]->points.begin(); it != graph[point]->points.end(); ++it) {
-                if(!isPaw(*it))
-                        return false;
-        }
-        return true;
-}
-
-int main() {
-        unsigned points;
-        unsigned lines;
-        while(cin >> points >> lines) {
-                graph = new Point * [points];
-                for (unsigned i = 0; i < points; i++) {
-                        graph[i] = new Point();
+int main(void){
+        int points, lines;
+        while(cin >> points >> lines){
+                Point ** p_points = new Point* [points];
+                for(int i = 0; i < points ; i++){
+                        p_points[i] = NULL;
                 }
 
-                for (unsigned i = 0; i < lines; i++) {
-                        unsigned x, y;
-                        cin >> x >> y;
-                        graph[x-1]->points.push_back(y-1);
-                        graph[y-1]->points.push_back(x-1);
-                        graph[x-1]->counter++;
-                        graph[y-1]->counter++;
-                }
-        
-                N = points;             
+                short first, second;
+                for(int i = 0; i < lines ; i++){
+                        cin >> first >> second;
+                        first--;
+                        second--;
+                        if(p_points[first]){
+                                p_points[first]->m_counter++;
+                                p_points[first]->m_points.push_back(second);
+                        }
+                        else{
+                                p_points[first] = new Point();
+                                p_points[first]->m_counter = 1;
+                                p_points[first]->m_points.push_back(second);
+                        }
 
-                bool found = false;
-                for (unsigned i = 0; i < N; i++) {
-                        if(graph[i]->counter == 4 && isBunny(i)) {
-                                cout << "YES" << endl;
-                                found = true;
-                                break;
+                        if(p_points[second]){
+                                p_points[second]->m_counter++;
+                                p_points[second]->m_points.push_back(first);
+                        }
+                        else{
+                                p_points[second] = new Point();
+                                p_points[second]->m_counter = 1;
+                                p_points[second]->m_points.push_back(first);
                         }
                 }
                 
-                if (!found)
-                        cout << "NO" << endl;
+                bool isBunny = false;
 
-                for (unsigned i = 0; i < points; i++) {
-                        delete graph[i];
+                for(int i = 0; i < points ; i++){
+                        if(p_points[i] && p_points[i]->m_counter==4){
+                                bool found = true;
+                                for(int j = 0; j < p_points[i]->m_points.size(); j++){
+                                        if(p_points[ p_points[i]->m_points[j] ]->m_counter != 1){
+                                                found = false;
+                                                break;
+                                        }
+                                }
+                                if(found) {
+                                        cout << "YES" << endl;
+                                        goto konec;                             
+                                }
+                        }
                 }
-                delete [] graph;
+                cout << "NO" << endl;
+                konec:
+                        ;
         }
-
         return 0;
 }