Submission #747147

# Submission time Handle Problem Language Result Execution time Memory
747147 2023-05-23T17:24:18 Z Rafi22 Connecting Supertrees (IOI20_supertrees) C++14
21 / 100
197 ms 27996 KB
#include <bits/stdc++.h>
#include "supertrees.h"

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

const int N=1007;

/*void build(vector<vector<int>>r)
{
    int n=sz(r);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++) cout<<r[i][j]<<" ";
        cout<<endl;
    }
}*/

bool odw[N];
int odw1[N];
vector<int>V,V1;
int G[N][N];
int n,c;
bool ok=1;

void dfs(int v)
{
    odw[v]=1;
    for(auto u:V) if(G[v][u]==0) ok=0;
    V.pb(v);
    for(int i=0;i<n;i++) if(G[v][i]>0&&!odw[i]) dfs(i);
}

void dfs1(int v)
{
    odw1[v]=c;
    for(auto u:V1) if(G[v][u]!=1) ok=0;
    V1.pb(v);
    for(int i=0;i<n;i++) if(G[v][i]==1&&!odw1[i]) dfs1(i);
}

int construct(vector<vector<int>>p)
{
    n=sz(p);
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) G[i][j]=p[i][j];
    vector<vector<int>>b(n,vector<int>(n,0));
    for(int i=0;i<n;i++)
    {
        if(odw[i]) continue;
        V.clear();
        dfs(i);
        memset(odw1,0,sizeof odw1);
        vector<int>cycle;
        for(auto v:V)
        {
            if(odw1[v]) continue;
            cycle.pb(v);
            c++;
            V1.clear();
            dfs1(v);
            for(auto a:V1)
            {
                for(auto b:V)
                {
                    if(odw1[b]!=c&&G[a][b]!=2) ok=0;
                }
            }
            for(int i=1;i<sz(V1);i++)
            {
                b[V1[i]][V1[i-1]]=1;
                b[V1[i-1]][V1[i]]=1;
            }
        }
        if(sz(cycle)>1)
        {
            for(int i=0;i<sz(cycle);i++)
            {
                b[cycle[i]][cycle[(i+1)%n]]=1;
                b[cycle[(i+1)%n]][cycle[i]]=1;
            }
        }
    }
    if(!ok) return 0;
    build(b);
    return 1;
}

/*int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<construct({{1, 1, 2, 2}, {1, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}});
    return 0;
}*/

# 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 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 2084 KB Output is correct
7 Correct 183 ms 27908 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 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 2084 KB Output is correct
7 Correct 183 ms 27908 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 8 ms 2036 KB Output is correct
13 Correct 172 ms 27904 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 1620 KB Output is correct
17 Correct 116 ms 18060 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 53 ms 8248 KB Output is correct
21 Correct 178 ms 27936 KB Output is correct
22 Correct 174 ms 27852 KB Output is correct
23 Correct 187 ms 27924 KB Output is correct
24 Correct 172 ms 27900 KB Output is correct
25 Correct 86 ms 17996 KB Output is correct
26 Correct 77 ms 17932 KB Output is correct
27 Correct 197 ms 27996 KB Output is correct
28 Correct 182 ms 27952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Incorrect 1 ms 320 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 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 46 ms 8196 KB Output is correct
5 Correct 179 ms 27880 KB Output is correct
6 Correct 173 ms 27852 KB Output is correct
7 Correct 194 ms 27948 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 43 ms 8200 KB Too many ways to get from 0 to 457, should be 0 found no less than 1
10 Halted 0 ms 0 KB -
# 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 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 2084 KB Output is correct
7 Correct 183 ms 27908 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 8 ms 2036 KB Output is correct
13 Correct 172 ms 27904 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 1620 KB Output is correct
17 Correct 116 ms 18060 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 53 ms 8248 KB Output is correct
21 Correct 178 ms 27936 KB Output is correct
22 Correct 174 ms 27852 KB Output is correct
23 Correct 187 ms 27924 KB Output is correct
24 Correct 172 ms 27900 KB Output is correct
25 Correct 86 ms 17996 KB Output is correct
26 Correct 77 ms 17932 KB Output is correct
27 Correct 197 ms 27996 KB Output is correct
28 Correct 182 ms 27952 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 316 KB Output is correct
32 Incorrect 1 ms 320 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 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 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 2084 KB Output is correct
7 Correct 183 ms 27908 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 8 ms 2036 KB Output is correct
13 Correct 172 ms 27904 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 1620 KB Output is correct
17 Correct 116 ms 18060 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 53 ms 8248 KB Output is correct
21 Correct 178 ms 27936 KB Output is correct
22 Correct 174 ms 27852 KB Output is correct
23 Correct 187 ms 27924 KB Output is correct
24 Correct 172 ms 27900 KB Output is correct
25 Correct 86 ms 17996 KB Output is correct
26 Correct 77 ms 17932 KB Output is correct
27 Correct 197 ms 27996 KB Output is correct
28 Correct 182 ms 27952 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 316 KB Output is correct
32 Incorrect 1 ms 320 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -