Submission #1241797


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5;

int N, M;
vector<int> G[MAXN + 10];

bool in_path[MAXN + 10];

int main() {
   scanf("%d%d", &N, &M);
   for(int i = 0; i < M; i++) {
      int u, v; scanf("%d%d", &u, &v);
      G[u].push_back(v);
      G[v].push_back(u);
   }
   deque<int> path;
   path.push_back(1); path.push_back(G[1][0]);
   in_path[1] = in_path[G[1][0]] = true;
   while(true) {
      int u = path.front(), v = path.back();
      int un = -1;
      for(int p : G[u]) {
         if(!in_path[p]) {
            un = p;
         }
      }
      if(un != -1) {
         in_path[un] = true;
         path.push_front(un);
         continue;
      }
      int vn = -1;
      for(int p :  G[v]) {
         if(!in_path[p]) {
            vn = p;
         }
      }
      if(vn != -1) {
         in_path[vn] = true;
         path.push_back(vn);
         continue;
      }
      break;
   }
   printf("%d\n", (int)path.size());
   for(int u : path) {
      printf("%d ", u);
   }
   printf("\n");
}

Submission Info

Submission Time
Task B - Hamiltonish Path
User ruhanhabib39
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1082 Byte
Status AC
Exec Time 46 ms
Memory 6784 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:12:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d%d", &N, &M);
                         ^
./Main.cpp:14:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
       int u, v; scanf("%d%d", &u, &v);
                                      ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt
Case Name Status Exec Time Memory
sample_01.txt AC 2 ms 2560 KB
sample_02.txt AC 2 ms 2560 KB
sample_03.txt AC 2 ms 2560 KB
subtask_1_01.txt AC 31 ms 4864 KB
subtask_1_02.txt AC 9 ms 3072 KB
subtask_1_03.txt AC 28 ms 4864 KB
subtask_1_04.txt AC 32 ms 4736 KB
subtask_1_05.txt AC 33 ms 4736 KB
subtask_1_06.txt AC 33 ms 4736 KB
subtask_1_07.txt AC 34 ms 5888 KB
subtask_1_08.txt AC 34 ms 5760 KB
subtask_1_09.txt AC 46 ms 6784 KB
subtask_1_10.txt AC 10 ms 3328 KB
subtask_1_11.txt AC 12 ms 3328 KB
subtask_1_12.txt AC 2 ms 2560 KB
subtask_1_13.txt AC 2 ms 2560 KB