Submission #117899

# Submission time Handle Problem Language Result Execution time Memory
117899 2019-06-17T11:13:19 Z 송준혁(#2882) Izlet (COI19_izlet) C++14
100 / 100
1000 ms 48832 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N;
int A[3030][3030];
int P[3030], C[3030];
vector<int> G[3030];
vector<pii> ans;

int FindP(int u){
    if (u == P[u]) return u;
    return P[u] = FindP(P[u]);
}

int FindC(int u){
    if (u == C[u]) return u;
    return C[u] = FindC(C[u]);
}

void dfs(int u, int p, int r, int w){
    if (A[w][p] != A[w][u] && A[w][p] != A[r][p] && A[r][u] == A[w][p]+1) P[FindP(r)] = FindP(u);
    if (w == 0){
        for (int v : G[u]){
            if (v == p) continue;
            dfs(v, u, r, v);
        }
        return;
    }
    for (int v : G[u]){
        if (v == p) continue;
        dfs(v, u, r, w);
    }
}

int main(){
    scanf("%*d %d", &N);
    for (int i=1; i<=N; i++) P[i] = i, C[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){
            if (FindP(i) != FindP(j)){
                P[FindP(i)] = FindP(j);
                G[i].push_back(j);
                G[j].push_back(i);
                ans.push_back(pii(i, j));
            }
        }
    }
    for (int i=1; i<=N; i++) for (int j=1; j<=N; j++){
        int u = FindP(i);
        int v = FindP(j);
        if (A[u][v] == 2){
            if (FindC(u) != FindC(v)){
                C[FindC(u)] = FindC(v);
                G[u].push_back(v);
                G[v].push_back(u);
                ans.push_back(pii(u, v));
            }
        }
    }
    for (int i=1; i<=N; i++) dfs(i, 0, i, 0);
    for (int i=1; i<=N; i++) printf("%d ", FindP(i));
    printf("\n");
    for (int i=0; i<N-1; i++) printf("%d %d\n", ans[i].first, ans[i].second);
    return 0;
}

Compilation message

izlet.cpp: In function 'int main()':
izlet.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%*d %d", &N);
     ~~~~~^~~~~~~~~~~~~~
izlet.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i][j]);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 793 ms 43124 KB Output is correct
3 Correct 865 ms 43128 KB Output is correct
4 Correct 878 ms 47480 KB Output is correct
5 Correct 866 ms 48832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 824 ms 36648 KB Output is correct
2 Correct 883 ms 43432 KB Output is correct
3 Correct 911 ms 41192 KB Output is correct
4 Correct 948 ms 40896 KB Output is correct
5 Correct 794 ms 43276 KB Output is correct
6 Correct 812 ms 38556 KB Output is correct
7 Correct 632 ms 32468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 793 ms 43124 KB Output is correct
3 Correct 865 ms 43128 KB Output is correct
4 Correct 878 ms 47480 KB Output is correct
5 Correct 866 ms 48832 KB Output is correct
6 Correct 824 ms 36648 KB Output is correct
7 Correct 883 ms 43432 KB Output is correct
8 Correct 911 ms 41192 KB Output is correct
9 Correct 948 ms 40896 KB Output is correct
10 Correct 794 ms 43276 KB Output is correct
11 Correct 812 ms 38556 KB Output is correct
12 Correct 632 ms 32468 KB Output is correct
13 Correct 1000 ms 37868 KB Output is correct
14 Correct 964 ms 38492 KB Output is correct
15 Correct 915 ms 43392 KB Output is correct
16 Correct 888 ms 38360 KB Output is correct
17 Correct 977 ms 38360 KB Output is correct
18 Correct 786 ms 43384 KB Output is correct
19 Correct 895 ms 43512 KB Output is correct
20 Correct 922 ms 43244 KB Output is correct
21 Correct 906 ms 37880 KB Output is correct
22 Correct 879 ms 43124 KB Output is correct
23 Correct 955 ms 38008 KB Output is correct
24 Correct 929 ms 38444 KB Output is correct
25 Correct 868 ms 43372 KB Output is correct