답안 #129631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
129631 2019-07-12T20:20:51 Z pzdba Izlet (COI19_izlet) C++14
0 / 100
848 ms 53456 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int a[3002][3002], p[3002], cnt[3002];
vector<pii> edge;
int root(int a){
    return p[a] == a?a:(p[a]=root(p[a]));
}
void merge(int a, int b){
    a = root(a), b = root(b);
    if(a != b) p[a] = b;
}
int main(){
    int t;
    scanf("%d", &t);
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) p[i] = i;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            scanf("%d", &a[i][j]);
            if(a[i][j] == 1 && root(i) != root(j)){
                edge.push_back(pii(i, j));
                merge(i, j);
            }
        }
    }

    int j = 1;
    for(int i=1;i<=n;i++){
        if(p[i] == i) cnt[i] = j++;
    }

    for(int i=1;i<=n;i++) printf("%d ", cnt[root(i)]);
    printf("\n");

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(a[i][j] == 2 && root(i) != root(j)){
                edge.push_back(pii(i, j));
                merge(i, j);
            }
        }
    }

    for(int i=0;i<n-1;i++) printf("%d %d\n", edge[i].first, edge[i].second);
}

Compilation message

izlet.cpp: In function 'int main()':
izlet.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &t);
     ~~~~~^~~~~~~~~~
izlet.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
izlet.cpp:21:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &a[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 848 ms 53456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -