제출 #10725

#제출 시각아이디문제언어결과실행 시간메모리
10725dohyun0324어르신 집배원 (BOI14_postmen)C++98
100 / 100
433 ms46892 KiB
#include<stdio.h>
#include<algorithm>
using namespace std;
int p,n,m,pos[500010],chv[500010],dap[500010],top,cnt,w,che[500010];
struct data
{
    int x,y,z;
    bool operator<(const data&r)const
    {
        return x<r.x;
    }
}arr[1000010];
void dfs(int x)
{
    int i,j;
    chv[x]=cnt;
    for(i=pos[x];;i++)
    {
        if(p)
        {
            dap[++top]=x;
            if(x==p)
            {
                for(j=1;j<top;j++) printf("%d ",dap[j]);
                printf("%d",dap[top]);
                printf("\n");
                p=0;
            }
            else
            {
                chv[x]=0;
                break;
            }
        }
        if(arr[i].x!=x) break;
        if(che[arr[i].z]) continue;
        che[arr[i].z]=1;
        if(chv[arr[i].y]==cnt)
        {
            p=arr[i].y;
            top=0;
            dap[++top]=x;
            i++;
            chv[x]=0;
            break;
        }
        dfs(arr[i].y);
    }
    pos[x]=i;
}
int main()
{
    int i,j,x,y;
    scanf("%d %d",&n,&m);
    for(i=1;i<=m;i++)
    {
        scanf("%d %d",&x,&y);
        w++; arr[w].x=x; arr[w].y=y; arr[w].z=i;
        w++; arr[w].x=y; arr[w].y=x; arr[w].z=i;
    }
    sort(arr+1,arr+w+1);
    for(i=1;i<=w;i++)
    {
        if(arr[i].x!=arr[i-1].x) pos[arr[i].x]=i;
    }
    for(i=1;i<=n;i++)
    {
        while(arr[pos[i]].x==i)
        {
            p=0; cnt++; dfs(i);
        }
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

postmen.cpp: In function 'int main()':
postmen.cpp:53:11: warning: unused variable 'j' [-Wunused-variable]
     int i,j,x,y;
           ^
postmen.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
postmen.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&x,&y);
         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...