답안 #502976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502976 2022-01-06T20:51:44 Z LouayFarah 슈퍼트리 잇기 (IOI20_supertrees) C++14
40 / 100
244 ms 22304 KB
#include "bits/stdc++.h"

using namespace std;

#define endl "\n"
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const long long MOD = 1e9+7;
const long long INF = 1e18;

int nx[4] = {0, 0, -1, 1};
int ny[4] = {1, -1, 0, 0};

void build(vector<vector<int>> b);

struct dsu
{
    vector<int> len;
    vector<int> link;

    void init(int n)
    {
        len.assign(n, 1);
        link.assign(n, 0);
        for(int i = 0; i<n; i++)
        {
            link[i] = i;
        }
    }

    int search(int x)
    {
        if(x!=link[x])
            link[x] = search(link[x]);
        return link[x];
    }

    bool check(int a, int b)
    {
        return search(a)==search(b);
    }

    void join(int a, int b)
    {
        a = search(a);
        b = search(b);

        if(a!=b)
        {
            if(len[a]<len[b])
                swap(a, b);

            len[a]+=len[b];
            link[b] = a;
        }
    }
};

int construct(vector<vector<int>> p)
{
    int n = int(p[0].size());

    vector<vector<int>> b(n, vector<int>(n, 0));

    dsu d;
    d.init(n);

    bool flag = false;

    for(int i = 0; i<n; i++)
    {
        for(int j = i+1; j<n; j++)
        {
            if(p[i][j]==1)
                d.join(i, j);
            if(p[i][j]==2)
            {
                d.join(i, j);
                flag = true;
            }
        }
    }

    vector<vector<int>> groups(n);
    for(int i = 0; i<n; i++)
    {
        int parent = d.search(i);
        groups[parent].pb(i);
    }

    /*for(int i = 0; i<n; i++)
    {
        cout << i << ": ";
        for(auto elt: groups[i])
            cout << elt << ' ';
        cout << endl;
    }*/


    if(!flag)
    {
        for(int i = 0; i<n; i++)
        {
            if(groups[i].empty())
                continue;

            int len = int(groups[i].size());
            for(int j = 0; j<len-1; j++)
            {

                int A = groups[i][j];
                int B = groups[i][j+1];

                b[A][B] = 1;
                b[B][A] = 1;
            }
        }
    }
    else
    {
        for(int i = 0; i<n; i++)
        {
            if(groups[i].empty())
                continue;

            int len = int(groups[i].size());
            vector<int> one, two;
            vector<bool> visited(n, false);
            for(int j = 0; j<len; j++)
            {
                for(int k = j+1; k<len; k++)
                {
                    int A = groups[i][j];
                    int B = groups[i][k];

                    if(p[A][B]==1)
                    {
                        if(!visited[A])
                        {
                            one.pb(A);
                            visited[A] = true;
                        }
                        if(!visited[B])
                        {
                            one.pb(B);
                            visited[B] = true;
                        }
                    }
                    if(p[A][B]==2)
                    {
                        if(!visited[A])
                        {
                            two.pb(A);
                            visited[A] = true;
                        }
                        if(!visited[B])
                        {
                            two.pb(B);
                            visited[B] = true;
                        }
                    }
                }
            }

            if(int(two.size())==2)
                return 0;

            for(int j = 0; j<int(one.size())-1; j++)
            {
                int A = one[j];
                int B = one[j+1];

                b[A][B] = 1;
                b[B][A] = 1;
            }
            for(int j = 0; j<int(two.size())-1; j++)
            {
                int A = two[j];
                int B = two[j+1];

                b[A][B] = 1;
                b[B][A] = 1;
            }

            if(int(two.size())>0)
            {
                int A = two[int(two.size())-1];
                int B = two[0];

                b[A][B] = 1;
                b[B][A] = 1;
            }
        }
    }

    for(int i = 0; i<n; i++)
    {
        for(int j = i+1; j<n; j++)
        {
            if(p[i][j]==0&&d.check(i, j))
                return 0;
            if(!d.check(i, j)&&p[i][j]!=0)
                return 0;
        }
    }

    for(int i = 0; i<n; i++)
    {
        b[i][i]  = 0;
    }

    build(b);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 8 ms 1100 KB Output is correct
7 Correct 179 ms 22008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 8 ms 1100 KB Output is correct
7 Correct 179 ms 22008 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 7 ms 1100 KB Output is correct
13 Correct 169 ms 22024 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 90 ms 12152 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 47 ms 5760 KB Output is correct
21 Correct 175 ms 22008 KB Output is correct
22 Correct 171 ms 22004 KB Output is correct
23 Correct 217 ms 22064 KB Output is correct
24 Correct 169 ms 22012 KB Output is correct
25 Correct 96 ms 12160 KB Output is correct
26 Correct 72 ms 12156 KB Output is correct
27 Correct 195 ms 22008 KB Output is correct
28 Correct 244 ms 22084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 7 ms 1100 KB Output is correct
9 Correct 191 ms 22168 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1100 KB Output is correct
13 Correct 175 ms 22020 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 117 ms 12156 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 45 ms 5720 KB Output is correct
22 Correct 175 ms 22276 KB Output is correct
23 Correct 172 ms 22084 KB Output is correct
24 Correct 198 ms 22016 KB Output is correct
25 Correct 73 ms 12424 KB Output is correct
26 Correct 83 ms 12408 KB Output is correct
27 Correct 178 ms 22052 KB Output is correct
28 Correct 197 ms 22304 KB Output is correct
29 Correct 73 ms 12328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 44 ms 5696 KB Output is correct
5 Correct 219 ms 22016 KB Output is correct
6 Correct 177 ms 22008 KB Output is correct
7 Correct 187 ms 22004 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 51 ms 5760 KB Output is correct
10 Correct 195 ms 22072 KB Output is correct
11 Correct 217 ms 22020 KB Output is correct
12 Correct 194 ms 22064 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Incorrect 0 ms 204 KB Too few ways to get from 0 to 4, should be 1 found 0
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 8 ms 1100 KB Output is correct
7 Correct 179 ms 22008 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 7 ms 1100 KB Output is correct
13 Correct 169 ms 22024 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 90 ms 12152 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 47 ms 5760 KB Output is correct
21 Correct 175 ms 22008 KB Output is correct
22 Correct 171 ms 22004 KB Output is correct
23 Correct 217 ms 22064 KB Output is correct
24 Correct 169 ms 22012 KB Output is correct
25 Correct 96 ms 12160 KB Output is correct
26 Correct 72 ms 12156 KB Output is correct
27 Correct 195 ms 22008 KB Output is correct
28 Correct 244 ms 22084 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 7 ms 1100 KB Output is correct
37 Correct 191 ms 22168 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 8 ms 1100 KB Output is correct
41 Correct 175 ms 22020 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 4 ms 716 KB Output is correct
45 Correct 117 ms 12156 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 45 ms 5720 KB Output is correct
50 Correct 175 ms 22276 KB Output is correct
51 Correct 172 ms 22084 KB Output is correct
52 Correct 198 ms 22016 KB Output is correct
53 Correct 73 ms 12424 KB Output is correct
54 Correct 83 ms 12408 KB Output is correct
55 Correct 178 ms 22052 KB Output is correct
56 Correct 197 ms 22304 KB Output is correct
57 Correct 73 ms 12328 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 5 ms 812 KB Output is correct
61 Correct 96 ms 12324 KB Output is correct
62 Correct 0 ms 204 KB Output is correct
63 Correct 0 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Incorrect 18 ms 3204 KB Answer gives possible 0 while actual possible 1
66 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 8 ms 1100 KB Output is correct
7 Correct 179 ms 22008 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 7 ms 1100 KB Output is correct
13 Correct 169 ms 22024 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 90 ms 12152 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 47 ms 5760 KB Output is correct
21 Correct 175 ms 22008 KB Output is correct
22 Correct 171 ms 22004 KB Output is correct
23 Correct 217 ms 22064 KB Output is correct
24 Correct 169 ms 22012 KB Output is correct
25 Correct 96 ms 12160 KB Output is correct
26 Correct 72 ms 12156 KB Output is correct
27 Correct 195 ms 22008 KB Output is correct
28 Correct 244 ms 22084 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 7 ms 1100 KB Output is correct
37 Correct 191 ms 22168 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 8 ms 1100 KB Output is correct
41 Correct 175 ms 22020 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 4 ms 716 KB Output is correct
45 Correct 117 ms 12156 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 45 ms 5720 KB Output is correct
50 Correct 175 ms 22276 KB Output is correct
51 Correct 172 ms 22084 KB Output is correct
52 Correct 198 ms 22016 KB Output is correct
53 Correct 73 ms 12424 KB Output is correct
54 Correct 83 ms 12408 KB Output is correct
55 Correct 178 ms 22052 KB Output is correct
56 Correct 197 ms 22304 KB Output is correct
57 Correct 73 ms 12328 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 44 ms 5696 KB Output is correct
62 Correct 219 ms 22016 KB Output is correct
63 Correct 177 ms 22008 KB Output is correct
64 Correct 187 ms 22004 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 51 ms 5760 KB Output is correct
67 Correct 195 ms 22072 KB Output is correct
68 Correct 217 ms 22020 KB Output is correct
69 Correct 194 ms 22064 KB Output is correct
70 Correct 0 ms 204 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Incorrect 0 ms 204 KB Too few ways to get from 0 to 4, should be 1 found 0
73 Halted 0 ms 0 KB -