답안 #747150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747150 2023-05-23T17:46:38 Z Rafi22 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
214 ms 28040 KB
#include <bits/stdc++.h>
#include "supertrees.h"

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

const int N=1007;

/*void build(vector<vector<int>>r)
{
    int n=sz(r);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++) cout<<r[i][j]<<" ";
        cout<<endl;
    }
}*/

bool odw[N];
int odw1[N];
vector<int>V,V1;
int G[N][N];
int n,c;
bool ok=1;

void dfs(int v)
{
    odw[v]=1;
    for(auto u:V) if(G[v][u]==0) ok=0;
    V.pb(v);
    for(int i=0;i<n;i++) if(G[v][i]>0&&!odw[i]) dfs(i);
}

void dfs1(int v)
{
    odw1[v]=c;
    for(auto u:V1) if(G[v][u]!=1) ok=0;
    V1.pb(v);
    for(int i=0;i<n;i++) if(G[v][i]==1&&!odw1[i]) dfs1(i);
}

int construct(vector<vector<int>>p)
{
    n=sz(p);
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) G[i][j]=p[i][j];
    vector<vector<int>>b(n,vector<int>(n,0));
    for(int i=0;i<n;i++)
    {
        if(odw[i]) continue;
        V.clear();
        dfs(i);
        memset(odw1,0,sizeof odw1);
        vector<int>cycle;
        for(auto v:V)
        {
            if(odw1[v]) continue;
            cycle.pb(v);
            c++;
            V1.clear();
            dfs1(v);
            for(int i=1;i<sz(V1);i++)
            {
                b[V1[i]][V1[i-1]]=1;
                b[V1[i-1]][V1[i]]=1;
            }
        }
        for(auto a:V)
        {
            for(auto b:V)
            {
                if(odw1[b]!=odw1[a]&&G[a][b]!=2) ok=0;
                if(odw1[b]==odw1[a]&&G[a][b]!=1) ok=0;
            }
        }
        if(sz(cycle)>2)
        {
            for(int i=0;i<sz(cycle);i++)
            {
                b[cycle[i]][cycle[(i+1)%sz(cycle)]]=1;
                b[cycle[(i+1)%sz(cycle)]][cycle[i]]=1;
            }
        }
        if(sz(cycle)==2) ok=0;
    }
    if(!ok) return 0;
    build(b);
    return 1;
}

/*int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<construct({{1, 1, 2, 2}, {1, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}});
    return 0;
}*/

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 1936 KB Output is correct
7 Correct 181 ms 26060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 1936 KB Output is correct
7 Correct 181 ms 26060 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 12 ms 1876 KB Output is correct
13 Correct 176 ms 25888 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 1496 KB Output is correct
17 Correct 105 ms 16032 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 7756 KB Output is correct
21 Correct 188 ms 25884 KB Output is correct
22 Correct 188 ms 25900 KB Output is correct
23 Correct 197 ms 25936 KB Output is correct
24 Correct 181 ms 25884 KB Output is correct
25 Correct 90 ms 16016 KB Output is correct
26 Correct 87 ms 16076 KB Output is correct
27 Correct 195 ms 26028 KB Output is correct
28 Correct 195 ms 26004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 280 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 9 ms 1988 KB Output is correct
9 Correct 180 ms 27832 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 8 ms 2060 KB Output is correct
13 Correct 172 ms 27908 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 1620 KB Output is correct
17 Correct 99 ms 18064 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 48 ms 8232 KB Output is correct
22 Correct 194 ms 27904 KB Output is correct
23 Correct 187 ms 27932 KB Output is correct
24 Correct 203 ms 27904 KB Output is correct
25 Correct 86 ms 17920 KB Output is correct
26 Correct 88 ms 17920 KB Output is correct
27 Correct 182 ms 27908 KB Output is correct
28 Correct 214 ms 28040 KB Output is correct
29 Correct 87 ms 17932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 47 ms 7724 KB Output is correct
5 Correct 188 ms 25976 KB Output is correct
6 Correct 183 ms 25904 KB Output is correct
7 Correct 193 ms 26016 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 46 ms 7728 KB Output is correct
10 Correct 180 ms 25932 KB Output is correct
11 Correct 176 ms 25996 KB Output is correct
12 Correct 187 ms 25932 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 51 ms 7704 KB Output is correct
17 Correct 183 ms 26004 KB Output is correct
18 Correct 192 ms 26004 KB Output is correct
19 Correct 188 ms 26000 KB Output is correct
20 Correct 178 ms 25884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 1936 KB Output is correct
7 Correct 181 ms 26060 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 12 ms 1876 KB Output is correct
13 Correct 176 ms 25888 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 1496 KB Output is correct
17 Correct 105 ms 16032 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 7756 KB Output is correct
21 Correct 188 ms 25884 KB Output is correct
22 Correct 188 ms 25900 KB Output is correct
23 Correct 197 ms 25936 KB Output is correct
24 Correct 181 ms 25884 KB Output is correct
25 Correct 90 ms 16016 KB Output is correct
26 Correct 87 ms 16076 KB Output is correct
27 Correct 195 ms 26028 KB Output is correct
28 Correct 195 ms 26004 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 280 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 9 ms 1988 KB Output is correct
37 Correct 180 ms 27832 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 316 KB Output is correct
40 Correct 8 ms 2060 KB Output is correct
41 Correct 172 ms 27908 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 5 ms 1620 KB Output is correct
45 Correct 99 ms 18064 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 48 ms 8232 KB Output is correct
50 Correct 194 ms 27904 KB Output is correct
51 Correct 187 ms 27932 KB Output is correct
52 Correct 203 ms 27904 KB Output is correct
53 Correct 86 ms 17920 KB Output is correct
54 Correct 88 ms 17920 KB Output is correct
55 Correct 182 ms 27908 KB Output is correct
56 Correct 214 ms 28040 KB Output is correct
57 Correct 87 ms 17932 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 5 ms 1608 KB Output is correct
61 Correct 105 ms 18208 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 51 ms 8204 KB Output is correct
66 Correct 91 ms 17920 KB Output is correct
67 Correct 92 ms 17996 KB Output is correct
68 Correct 89 ms 17940 KB Output is correct
69 Correct 85 ms 17980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 1936 KB Output is correct
7 Correct 181 ms 26060 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 12 ms 1876 KB Output is correct
13 Correct 176 ms 25888 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 1496 KB Output is correct
17 Correct 105 ms 16032 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 7756 KB Output is correct
21 Correct 188 ms 25884 KB Output is correct
22 Correct 188 ms 25900 KB Output is correct
23 Correct 197 ms 25936 KB Output is correct
24 Correct 181 ms 25884 KB Output is correct
25 Correct 90 ms 16016 KB Output is correct
26 Correct 87 ms 16076 KB Output is correct
27 Correct 195 ms 26028 KB Output is correct
28 Correct 195 ms 26004 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 280 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 9 ms 1988 KB Output is correct
37 Correct 180 ms 27832 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 316 KB Output is correct
40 Correct 8 ms 2060 KB Output is correct
41 Correct 172 ms 27908 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 5 ms 1620 KB Output is correct
45 Correct 99 ms 18064 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 48 ms 8232 KB Output is correct
50 Correct 194 ms 27904 KB Output is correct
51 Correct 187 ms 27932 KB Output is correct
52 Correct 203 ms 27904 KB Output is correct
53 Correct 86 ms 17920 KB Output is correct
54 Correct 88 ms 17920 KB Output is correct
55 Correct 182 ms 27908 KB Output is correct
56 Correct 214 ms 28040 KB Output is correct
57 Correct 87 ms 17932 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 47 ms 7724 KB Output is correct
62 Correct 188 ms 25976 KB Output is correct
63 Correct 183 ms 25904 KB Output is correct
64 Correct 193 ms 26016 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 46 ms 7728 KB Output is correct
67 Correct 180 ms 25932 KB Output is correct
68 Correct 176 ms 25996 KB Output is correct
69 Correct 187 ms 25932 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 51 ms 7704 KB Output is correct
74 Correct 183 ms 26004 KB Output is correct
75 Correct 192 ms 26004 KB Output is correct
76 Correct 188 ms 26000 KB Output is correct
77 Correct 178 ms 25884 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 5 ms 1608 KB Output is correct
81 Correct 105 ms 18208 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 51 ms 8204 KB Output is correct
86 Correct 91 ms 17920 KB Output is correct
87 Correct 92 ms 17996 KB Output is correct
88 Correct 89 ms 17940 KB Output is correct
89 Correct 85 ms 17980 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 5 ms 1604 KB Output is correct
93 Correct 95 ms 18064 KB Output is correct
94 Correct 1 ms 316 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 0 ms 340 KB Output is correct
97 Correct 24 ms 5624 KB Output is correct
98 Correct 91 ms 18020 KB Output is correct
99 Correct 89 ms 17984 KB Output is correct
100 Correct 90 ms 17920 KB Output is correct
101 Correct 101 ms 17980 KB Output is correct
102 Correct 86 ms 18052 KB Output is correct
103 Correct 81 ms 18068 KB Output is correct
104 Correct 88 ms 18064 KB Output is correct
105 Correct 100 ms 18068 KB Output is correct