foru

                Never    
C
       
# include <stdio.h>

int main (void){
    int i;
    int N,M; //N is the number of studets, M is the number of exchanges
    scanf("%d%d",&N,&M);
    int seat[1005]; //starts from seat1
    int temp;
    int check2;
    int sign=0;
    for(int i=1; i<=N; i++){

        seat[i] = i;
    } //give number 1,2,3...to seat

    int apt1,apt2; //apt is the student called to exchange his seat
    if(M!=0)
        {for(int i=1; i<=M; i++){

            sign=0;
            scanf("%d%d",&apt1,&apt2);

            for(int check=1; check<=N; check++){

                if(apt1<apt2){
                    temp=apt2;
                    apt2=apt1;
                    apt1=temp;

                }

                if(seat[check]==apt1){


                    for(int check2=1; check2<=N; check2++){

                        if(seat[check2]==apt2)
                        {
                            seat[check]=apt2;
                            seat[check2]=apt1;
                            sign=1;
                            break;
                        }
                    }

                }

                if(sign==1)
                {
                    break;
                }
            }
        }

        for(int i=1; i<=N-1; i++){

            printf("%d ",seat[i]);
        }
        printf("%d",seat[N]);
        printf("\n");
    }
    else{

        for(int i=1; i<=N-1; i++){

            printf("%d ",seat[i]);
        }
        printf("%d",seat[N]);
        printf("\n");
    }
}

Raw Text