Submission #800090

# Submission time Handle Problem Language Result Execution time Memory
800090 2023-08-01T10:01:20 Z PixelCat Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
0 ms 212 KB
#include "supertrees.h"

#ifdef NYAOWO
#include "grader.cpp"
#endif

#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
// #define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 1000;

vector<vector<int>> answer;
inline void add_edge(int a, int b) {
    answer[a][b] = answer[b][a] = 1;
}

struct DSU {
    int p[MAXN + 10];
    void init() {
        memset(p, -1, sizeof(p));
    }
    int find(int n) {
        if(p[n] < 0) return n;
        return p[n] = find(p[n]);
    }
    bool uni(int a, int b) {
        a = find(a); b = find(b);
        if(a == b) return false;
        p[b] = a;
        return true;
    }
    bool same(int a, int b) {
        return find(a) == find(b);
    }
    bool lead(int n) {
        return p[n] < 0;
    }
} dsu;

int construct(vector<vector<int>> p) {
    int n = sz(p);
    For(i, 0, n - 1) For(j, 0, n - 1) if(p[i][j] == 3) return 0;
    answer = vector<vector<int>>(n, vector<int>(n, 0));

    // phase 1: find all CC
    dsu.init();
    For(i, 0, n - 1) For(j, 0, n - 1) {
        if(p[i][j]) dsu.uni(i, j);
    }
    vector<vector<int>> vcc;
    For(i, 0, n - 1) if(dsu.lead(i)) {
        vcc.eb();
        For(j, 0, n - 1) if(dsu.same(i, j)) {
            vcc.back().eb(j);
        }
    }

    // phase 2: solve for each CC
    for(vector<int> &cc:vcc) if(sz(cc) > 1) {
        int mask = 0;
        for(auto &v1:cc) for(auto &v2:cc) if(v1 != v2) {
            mask |= (1 << p[v1][v2]);
        }
        if(mask & 1) return 0;
        // if(mask == 2) {
        //     int rt = cc.back();
        //     cc.pop_back();
        //     for(auto &i:cc) {
        //         add_edge(i, rt);
        //     }
        // } else 
        // if(mask == 4) {
            For(i, 1, sz(cc) - 1) {
                add_edge(cc[i], cc[i - 1]);
            }
            add_edge(cc.front(), cc.back());
        // }
    }

    build(answer);
    return 1;
}
# 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 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 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 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 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 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
5 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 Incorrect 0 ms 212 KB Too many ways to get from 1 to 4, should be 1 found no less than 2
4 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 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 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 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -