Submission #1047571

# Submission time Handle Problem Language Result Execution time Memory
1047571 2024-08-07T14:06:07 Z idas Connecting Supertrees (IOI20_supertrees) C++17
19 / 100
118 ms 24316 KB
#include "supertrees.h"
#include "bits/stdc++.h"
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define sz(x) ((int)((x).size()))
#define pb push_back

using namespace std;
typedef long long ll;
typedef vector<int> vi;

const int MxN=1e3+10;
int n, par[MxN], cyc[MxN];
bool v[MxN];

int fnd(int u) {
    return par[u]=par[u]==u?u:fnd(par[u]);
}

void mrg(int a, int b) {
    a=fnd(a); b=fnd(b);
    if(a==b) return;
    par[a]=b;
}

int construct(std::vector<std::vector<int>> p) {
    n=sz(p);

    FOR(i, 0, n) par[i]=i;

    vector b(n, vector(n, 0));
    FOR(i, 0, n) {
        FOR(j, 0, n) {
            if(p[i][j]==1) {
                b[i][j]=b[j][i]=1;
                mrg(i, j);
            }
        }
    }

    vector used(n, false);
    FOR(i, 0, n) {
        int u=fnd(i);
        if(used[u]) continue;

        used[u]=true;
        cyc[u]=i;

        int cn=1, lst=u, frst=u;
        FOR(j, 0, n) {
            int w=fnd(j);
            if(used[w]) continue;

            if(p[u][w]==2) {
                used[w]=true;
                cyc[w]=i;
                cn++;

                b[lst][w]=b[w][lst]=1;
                lst=w;
            }
        }
        b[lst][frst]=b[frst][lst]=1;

        if(cn==2) {
            return 0;
        }
    }

    bool ok=true;
    FOR(i, 0, n) {
        FOR(j, 0, n) {
            int u=fnd(i), w=fnd(j);
            if(u==w) ok&=p[u][w]==1;
            else if(cyc[u]==cyc[w]) ok&=p[u][w]==2;
            else ok&=p[u][w]==0;
        }
    }

    FOR(i, 0, n) b[i][i]=0;

    if(!ok) return 0;

    build(b);

    return 1;
}
/*
Example 1:
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1

Example 2:
2
1 0
0 1

Example 3:
2
1 3
3 1

5
1 1 2 2 2
1 1 2 2 2
2 2 1 2 2
2 2 2 1 1
2 2 2 1 1
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 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 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 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 348 KB Output is correct
2 Correct 0 ms 372 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 118 ms 24076 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 103 ms 24316 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 444 KB Output is correct
16 Correct 2 ms 936 KB Output is correct
17 Correct 47 ms 14072 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 26 ms 6216 KB Output is correct
22 Correct 98 ms 24136 KB Output is correct
23 Correct 101 ms 23988 KB Output is correct
24 Correct 101 ms 24148 KB Output is correct
25 Correct 46 ms 14084 KB Output is correct
26 Correct 46 ms 14212 KB Output is correct
27 Correct 96 ms 24144 KB Output is correct
28 Correct 99 ms 24148 KB Output is correct
29 Correct 92 ms 14160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 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 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 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 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -