Submission #825332

# Submission time Handle Problem Language Result Execution time Memory
825332 2023-08-14T17:54:00 Z HorizonWest Connecting Supertrees (IOI20_supertrees) C++17
19 / 100
208 ms 24156 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);

    vector <vector<int>> g, 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])
                return 0;

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

    map <int, int> mp, pass; int idx = 0;

    for(int i = 0; i < n; i++)
    {
        int x = St.find(i);
        if(mp[x] == 0)
        {
            idx++;
            mp[x] = idx;
            g.push_back(vector <int> ());
        }
        g[mp[x]-1].push_back(i);
    }

    /*for(int i = 0; i < (int) g.size(); i++)
    {
        for(int j = 0; j < g[i].size(); j++)
        {
            for(int k = j+1; k < g[i].size(); k++)
            {
                if(p[g[i][j]][g[i][k]] != 1)
                    return 0;
            }
            pass[g[i][j]] = i+1;
        }

        for(int j = 0; j < g[i].size() - 1; j++)
        {
            ans[g[i][j]][g[i][j+1]] = 1;
            ans[g[i][j+1]][g[i][j]] = 1;
        }

        int x = g[i][0]; vector <int> s;

        for(int j = 0; j < n; j++)
        {
            if(p[x][j] == 2)
            {
                if(pass[j] != 0)
                    return 0;
                pass[j] = i+1;
                s.push_back(j);
                St.unite(x, j);
            }
        }

        if(s.size() > 0 && s.size() < 3) return 0;

        if(s.size() > 0)
        {
            ans[x][s[0]] = 1;
            ans[s[0]][x] = 1;

            int mod = s.size();

            for(int j = 0; j < (int) s.size(); j++)
            {
                ans[s[j]][s[(j+1) % mod]] = 1;
                ans[s[(j+1) % mod]][s[j]] = 1;
            }

            for(int j = 0; j < g[i].size(); j++)
            {
                for(int k = 0; k < n; k++) if(p[g[i][j]][k] != 0)
                {
                    if(pass[k] != i + 1) return 0;
                }
            }

            for(int j = 0; j < s.size(); j++)
            {
                for(int k = 0; k < n; k++) if(p[s[j]][k] != 0)
                {
                    if(pass[k] != i + 1) return 0;
                }
            }
        }
    }*/

    for(int i = 0; i < n; i++) if(St.sz(i) == 1)
    {
        vector <int> s; s.push_back(i);
        map <int, int> mk; mk[i] = 1;

        for(int j = 0; j < n; j++) if(p[i][j] == 2)
        {
            mk[j] = 1;
            s.push_back(j);
            St.unite(i, j);
        }

        int m = (int) s.size();

        if(m != 1)
        {
            if(m == 2) return 0;

            for(int j = 0; j < m; j++)
            {
                for(int k = 0; k < n; k++)
                {
                    if(((p[s[j]][k] != 0) ^ (mk[k])))
                        return 0;
                }
            }

            for(int j = 0; j < m; j++)
            {
                ans[s[j]][s[(j+1) % m]] = 1;
                ans[s[(j+1) % m]][s[j]] = 1;
            }
        }
    }

    build(ans);
    return 1;
}









# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 6 ms 1192 KB Output is correct
9 Correct 152 ms 22132 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1220 KB Output is correct
13 Correct 208 ms 22116 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 92 ms 12300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 42 ms 5740 KB Output is correct
22 Correct 182 ms 24048 KB Output is correct
23 Correct 183 ms 24060 KB Output is correct
24 Correct 192 ms 24156 KB Output is correct
25 Correct 72 ms 14200 KB Output is correct
26 Correct 73 ms 14228 KB Output is correct
27 Correct 182 ms 24064 KB Output is correct
28 Correct 203 ms 24048 KB Output is correct
29 Correct 64 ms 14212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Too few ways to get from 1 to 2, should be 1 found 0
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -