Advertisement
tomalikem

EUL.cpp

May 10th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2. // we're big guys now, let's use already implemeted list
  3. // you might want check this out: http://www.cplusplus.com/reference/list/list/#functions
  4. #include <list>
  5.  
  6. using namespace std;
  7.  
  8. enum graph_type {
  9.     EULER = 1,
  10.     HALF = 2,
  11.     NO = 3
  12. };
  13.  
  14.  
  15. graph_type check_graph(list<int> graph[], int n) {
  16.  
  17.     int eu=0;
  18.    for(int i=0; i<n ; i++)
  19.    {
  20.        if(graph[i].size()%2==1)
  21.        {
  22.            eu++;
  23.        }
  24.    }
  25.  
  26.  
  27.     if ( eu==0 ) {
  28.         return EULER;
  29.     } else if ( eu==1 ) {
  30.         return HALF;
  31.     } else {
  32.         return NO;
  33.     }
  34. }
  35.  
  36. int main() {
  37.     int Z;
  38.  
  39.     scanf("%d", &Z);
  40.  
  41.     while (Z--) {
  42.  
  43.         int n, m;
  44.         int u, v;
  45.         scanf("%d %d", &n, &m);
  46.         list<int> *graph = new list<int>[n+1];
  47.         for(int i=0; i<m; i++) {
  48.             scanf("%d %d", &u, &v);
  49.             graph[u].push_back(v);
  50.             graph[v].push_back(u);
  51.         }
  52.  
  53.         graph_type result = check_graph(graph, n);
  54.         switch(result) {
  55.             case EULER:
  56.                 printf("EULER\n");
  57.                 break;
  58.             case HALF:
  59.                 printf("HALF\n");
  60.                 break;
  61.             case NO:
  62.                 printf("NO\n");
  63.                 break;
  64.         }
  65.         delete [] graph;
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement