답안 #1203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1203 2013-06-29T15:56:28 Z gs12117 탐사 (KOI13_probe) C++
19 / 19
2 ms 376 KB
#include<stdio.h>
int a[1010][3];
int edge[162][3];
int len[42];
int uft[42][2];
int en;
int n,m;
int f(int x){
    if(uft[x][0]==x)return x;
    f(uft[x][0]);
    uft[x][1]+=uft[uft[x][0]][1];
    uft[x][0]=uft[uft[x][0]][0];
    return uft[x][0];
}
int main(){
    int i,j,k,l,t;
    scanf("%d%d",&m,&n);
    for(i=0;i<=m;i++){
        uft[i][0]=i;
    }
    for(i=0;i<n;i++){
        scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
        a[i][0]--;
        if(f(a[i][0])==f(a[i][1])){
            if(uft[a[i][1]][1]!=uft[a[i][0]][1]+a[i][2]){
                printf("NONE");
                return 0;
            }
        }
        else{
            t=f(a[i][1]);
            uft[t][1]=a[i][2]-uft[a[i][1]][1];
            uft[t][0]=a[i][0];
            edge[en][0]=a[i][0];
            edge[en][1]=a[i][1];
            edge[en][2]=a[i][2];
            en++;
            edge[en][0]=a[i][1];
            edge[en][1]=a[i][0];
            edge[en][2]=-a[i][2];
            en++;
        }
    }
    for(i=0;i<m;i++){
        edge[en][0]=i;
        edge[en][1]=i+1;
        edge[en][2]=1;
        en++;
        edge[en][0]=i+1;
        edge[en][1]=i;
        edge[en][2]=0;
        en++;
    }
    for(i=1;i<=m;i++){
        len[i]=10000000;
    }
    for(i=0;i<m+7;i++){
        t=0;
        for(j=0;j<en;j++){
            if(len[edge[j][1]]>len[edge[j][0]]+edge[j][2]){
                len[edge[j][1]]=len[edge[j][0]]+edge[j][2];
                t++;
            }
        }
        if(t==0)break;
    }
    if(i==m+7){
        printf("NONE");
    }
    else{
        for(i=0;i<m;i++){
            if(len[i]==len[i+1])printf("-");
            else printf("#");
        }
    }
}

Compilation message

probe.cpp: In function 'int main()':
probe.cpp:16:13: warning: unused variable 'k' [-Wunused-variable]
     int i,j,k,l,t;
             ^
probe.cpp:16:15: warning: unused variable 'l' [-Wunused-variable]
     int i,j,k,l,t;
               ^
probe.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&m,&n);
     ~~~~~^~~~~~~~~~~~~~
probe.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 296 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct