답안 #825367

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825367 2023-08-14T18:42:55 Z HorizonWest 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
169 ms 26112 KB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define db double
#define ll __int128
//#define int long long
#define pb push_back
#define fs first
#define sd second
#define Mod long(1e9 + 7)
#define all(x) x.begin(), x.end()
#define unvisited long(-1)
#define Eps double(1e-9)
#define _for(i, n) for(int i = 0; i < (n); i++)
#define dbg(x) cout << #x ": " << x << endl;

const int Max = 1e6 + 7, Inf = 1e9 + 7;

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

struct DSU
{
    vector <int> link, size;

    int find(int x)
    {
        while(x != link[x]) x = link[x];
        return x;
    }

    int sz(int x)
    {
        return size[find(x)];
    }

    bool same(int a, int b)
    {
        return find(a) == find(b);
    }

    void unite(int a, int b)
    {
        a = find(a); b = find(b);
        if(a == b) return;
        if(size[a] < size[b]) swap(a, b);
        link[b] = a; size[a] += size[b];
    }

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

int construct(std::vector<std::vector<int>> p)
{
    int n = p.size(); DSU St(n), Fx(n);

    vector <vector<int>> g(n, vector <int> (n, 0)),
                        ans(n, vector <int> (n, 0));

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++) if(j != i)
        {
            if(p[i][j] != p[j][i] || p[i][j] == 3)
                return 0;

            if(p[i][j] != 0)
                St.unite(i, j);
        }
    }

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

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(p[i][j] == 1 && !Fx.same(i, j))
            {
                Fx.unite(i, j);
                ans[i][j] = ans[j][i] = 1;
            }
        }
    }

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
            if(Fx.same(i, j) && p[i][j] == 2) return 0;
    }

    map <int, int> mp;

    for(int i = 0; i < n; i++)
    {
        if(mp[St.find(i)]) continue;
        mp[St.find(i)] = 1;

        vector <int> s;

        for(int j = 0; j < n; j++)
        {
            if(St.same(i, j) && St.find(j) == j)
            {
                s.push_back(j);
            }
        }
        int m = s.size();

        if(m > 1)
        {
            int x = St.find(i);
            ans[x][s[0]] = ans[s[0]][x] = 1;
            for(int i = 0; i < m; i++)
                ans[s[i]][s[(i+1)%m]] = ans[s[(i+1)%m]][s[i]] = 1;
        }
    }

    build(ans);
    return 1;
}









# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 212 KB Output is correct
6 Correct 7 ms 1308 KB Output is correct
7 Correct 159 ms 25960 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1308 KB Output is correct
7 Correct 159 ms 25960 KB Output is correct
8 Correct 0 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 212 KB Output is correct
12 Correct 7 ms 1296 KB Output is correct
13 Correct 157 ms 25960 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 71 ms 16008 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 6760 KB Output is correct
21 Correct 159 ms 25916 KB Output is correct
22 Correct 158 ms 25984 KB Output is correct
23 Correct 169 ms 26024 KB Output is correct
24 Correct 156 ms 25980 KB Output is correct
25 Correct 62 ms 16008 KB Output is correct
26 Correct 60 ms 16016 KB Output is correct
27 Correct 164 ms 25924 KB Output is correct
28 Correct 157 ms 26112 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 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Too few ways to get from 0 to 1, should be 2 found 0
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 212 KB Output is correct
6 Correct 7 ms 1308 KB Output is correct
7 Correct 159 ms 25960 KB Output is correct
8 Correct 0 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 212 KB Output is correct
12 Correct 7 ms 1296 KB Output is correct
13 Correct 157 ms 25960 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 71 ms 16008 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 6760 KB Output is correct
21 Correct 159 ms 25916 KB Output is correct
22 Correct 158 ms 25984 KB Output is correct
23 Correct 169 ms 26024 KB Output is correct
24 Correct 156 ms 25980 KB Output is correct
25 Correct 62 ms 16008 KB Output is correct
26 Correct 60 ms 16016 KB Output is correct
27 Correct 164 ms 25924 KB Output is correct
28 Correct 157 ms 26112 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 212 KB Output is correct
6 Correct 7 ms 1308 KB Output is correct
7 Correct 159 ms 25960 KB Output is correct
8 Correct 0 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 212 KB Output is correct
12 Correct 7 ms 1296 KB Output is correct
13 Correct 157 ms 25960 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 71 ms 16008 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 6760 KB Output is correct
21 Correct 159 ms 25916 KB Output is correct
22 Correct 158 ms 25984 KB Output is correct
23 Correct 169 ms 26024 KB Output is correct
24 Correct 156 ms 25980 KB Output is correct
25 Correct 62 ms 16008 KB Output is correct
26 Correct 60 ms 16016 KB Output is correct
27 Correct 164 ms 25924 KB Output is correct
28 Correct 157 ms 26112 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -