Language: C

#include <stdio.h>
#include <string.h>
#define MaxSize 100000
char neighbour[MaxSize][MaxSize];
char visited[MaxSize];
char nbCount[MaxSize];
int startPath[MaxSize];
int endPath[MaxSize];
int startPathLen = 0;
int endPathLen = 0;

void searchEnd(int end, int pathArr[], int * pLength) {
    char allNbSearched = 0;
    char foundNew = 0;
    while(!foundNew && !allNbSearched) {
        for(int i = 0; i < nbCount[end]; i++) {
            int newEnd = neighbour[end][i];
            if(!visited[newEnd]) {
                end = newEnd;
                visited[newEnd] = 1;
                foundNew = 1;
                allNbSearched = 0;
                pathArr[*pLength] = newEnd;
                (*pLength)++;
                break; //for
            }
        }
        allNbSearched = 1;
    }
}
int main(int argc, const char * argv[]) {
    int N, M;
    memset(neighbour, 0, MaxSize * MaxSize);
    memset(visited, 0, MaxSize);
    memset(nbCount, 0, MaxSize);
    scanf("%d%d", &N, &M);
    int start = -1, end = -1;
    for(int i = 1; i < M; i++) {
        scanf("%d%d", &start, &end);
        neighbour[start][nbCount[start]] = end;
        neighbour[end][nbCount[end]] = start;
        nbCount[start]++;
        nbCount[end]++;
    }
    
    visited[start] = visited[end] = 1;
    searchEnd(start, startPath, &startPathLen);
    searchEnd(end, endPath, &endPathLen);
    
    printf("%d\n", startPathLen + endPathLen + 2);
    for(int i = 0; i < startPathLen; i++)
        printf("%d ", startPath[i]);
    printf("%d %d ", start, end);
    for(int i = 0; i < endPathLen; i++)
        printf("%d ", endPath[i]);
    printf("\n");
    return 0;
}

Compiler output:
main.c: In function 'main':
main.c:33:34: warning: integer overflow in expression of type 'int' results in '1410065408' [-Woverflow]
   33 |     memset(neighbour, 0, MaxSize * MaxSize);
      |                                  ^
/tmp/cczSm0OR.o: in function `searchEnd':
main.c:(.text+0x58): relocation truncated to fit: R_X86_64_PC32 against symbol `visited' defined in .bss section in /tmp/cczSm0OR.o
main.c:(.text+0x72): relocation truncated to fit: R_X86_64_PC32 against symbol `visited' defined in .bss section in /tmp/cczSm0OR.o
main.c:(.text+0xbb): relocation truncated to fit: R_X86_64_PC32 against symbol `nbCount' defined in .bss section in /tmp/cczSm0OR.o
/tmp/cczSm0OR.o: in function `main':
main.c:(.text+0x11b): relocation truncated to fit: R_X86_64_PC32 against symbol `visited' defined in .bss section in /tmp/cczSm0OR.o
main.c:(.text+0x134): relocation truncated to fit: R_X86_64_PC32 against symbol `nbCount' defined in .bss section in /tmp/cczSm0OR.o
main.c:(.text+0x1a6): relocation truncated to fit: R_X86_64_PC32 against symbol `nbCount' defined in .bss section in /tmp/cczSm0OR.o
main.c:(.text+0x1dc): relocation truncated to fit: R_X86_64_PC32 against symbol `nbCount' defined in .bss section in /tmp/cczSm0OR.o
main.c:(.text+0x20d): relocation truncated to fit: R_X86_64_PC32 against symbol `nbCount' defined in .bss section in /tmp/cczSm0OR.o
main.c:(.text+0x21f): relocation truncated to fit: R_X86_64_PC32 against symbol `nbCount' defined in .bss section in /tmp/cczSm0OR.o
main.c:(.text+0x22f): relocation truncated to fit: R_X86_64_PC32 against symbol `nbCount' defined in .bss section in /tmp/cczSm0OR.o
main.c:(.text+0x241): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status