답안 #749823

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
749823 2023-05-28T14:39:55 Z Username4132 Izlet (COI19_izlet) C++14
100 / 100
777 ms 74808 KB
#include<iostream>
#include<vector>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back

const int MAXN=3010;
int subtask, n, comInd, arr[MAXN][MAXN], com[MAXN], low[MAXN], tin[MAXN], color[MAXN], par[MAXN], lst[MAXN], tm, ch, cnt;
bool solved[MAXN][MAXN], vis[MAXN];
vector<int> els[MAXN], g[MAXN], st;

void dfs1(int v){
    com[v]=comInd;
    forn(to, n) if(arr[v][to]==1 && !com[to]) dfs1(to);
}

void dfs2(int v){
    tin[v]=low[v]=tm++;
    vis[v]=true;
    st.PB(v);
    forn(to, comInd) if(arr[v][els[to][0]]==2){
        if(vis[els[to][0]]) low[v]=min(low[v], tin[els[to][0]]);
        else{
            dfs2(els[to][0]);
            low[v]=min(low[v], low[els[to][0]]);
            if(v==els[0][0] || low[els[to][0]]>=tin[v]){
                while(!st.empty() && st.back()!=v){
                    g[st.back()].PB(v);
                    g[v].PB(st.back());
                    st.pop_back();
                }
            }
        }
    }
}

void dfs3(int v, int p){
    par[v]=p;
    for(int to:g[v]) if(color[to]!=n && to!=p){
        dfs3(to, v);
    }
    lst[color[v]]=v;
}

void dfs4(int v, int p){
    int col=-1;
    forn(i, n) lst[i]=-1;
    dfs3(v, v);
    forn(i, n) if(lst[i]!=-1 && arr[v][lst[i]]==arr[v][par[lst[i]]]) col=i;
    if(col==-1) col=cnt++;
    color[v]=col;    
    for(int to:g[v]) if(to!=p) dfs4(to, v);
}

int main(){
    scanf("%d", &subtask);
    scanf("%d", &n);
    forn(i, n) forn(j, n) scanf("%d", &arr[i][j]);
    forn(i, n) if(!com[i]) ++comInd, dfs1(i);
    forn(i, n) els[com[i]-1].PB(i);

    dfs2(els[0][0]);
    forn(i, comInd) forsn(j, 1, els[i].size()){
        g[els[i][0]].PB(els[i][j]);
        g[els[i][j]].PB(els[i][0]);
    }

    forn(i, n) color[i]=n;
    dfs4(0, 0);
    forn(i, n) printf("%d ", color[i]+1);
    printf("\n");
    forn(i, n) for(int j:g[i]) if(j>i) printf("%d %d\n", i+1, j+1);
}

Compilation message

izlet.cpp: In function 'int main()':
izlet.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%d", &subtask);
      |     ~~~~~^~~~~~~~~~~~~~~~
izlet.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
izlet.cpp:59:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     forn(i, n) forn(j, n) scanf("%d", &arr[i][j]);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 668 ms 53884 KB Output is correct
3 Correct 648 ms 53964 KB Output is correct
4 Correct 627 ms 53564 KB Output is correct
5 Correct 628 ms 53560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 660 ms 53820 KB Output is correct
2 Correct 639 ms 53780 KB Output is correct
3 Correct 741 ms 74044 KB Output is correct
4 Correct 737 ms 74808 KB Output is correct
5 Correct 624 ms 53644 KB Output is correct
6 Correct 674 ms 60688 KB Output is correct
7 Correct 493 ms 49480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 668 ms 53884 KB Output is correct
3 Correct 648 ms 53964 KB Output is correct
4 Correct 627 ms 53564 KB Output is correct
5 Correct 628 ms 53560 KB Output is correct
6 Correct 660 ms 53820 KB Output is correct
7 Correct 639 ms 53780 KB Output is correct
8 Correct 741 ms 74044 KB Output is correct
9 Correct 737 ms 74808 KB Output is correct
10 Correct 624 ms 53644 KB Output is correct
11 Correct 674 ms 60688 KB Output is correct
12 Correct 493 ms 49480 KB Output is correct
13 Correct 660 ms 54668 KB Output is correct
14 Correct 726 ms 61776 KB Output is correct
15 Correct 645 ms 53744 KB Output is correct
16 Correct 678 ms 58076 KB Output is correct
17 Correct 723 ms 60028 KB Output is correct
18 Correct 632 ms 53728 KB Output is correct
19 Correct 645 ms 53744 KB Output is correct
20 Correct 672 ms 53740 KB Output is correct
21 Correct 655 ms 54336 KB Output is correct
22 Correct 639 ms 53856 KB Output is correct
23 Correct 643 ms 54356 KB Output is correct
24 Correct 777 ms 60748 KB Output is correct
25 Correct 655 ms 53708 KB Output is correct