답안 #747149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747149 2023-05-23T17:43:51 Z Rafi22 슈퍼트리 잇기 (IOI20_supertrees) C++14
56 / 100
200 ms 26096 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(int i=1;i<sz(V1);i++)
            {
                b[V1[i]][V1[i-1]]=1;
                b[V1[i-1]][V1[i]]=1;
            }
        }
        for(auto a:V)
        {
            for(auto b:V)
            {
                if(odw1[b]!=odw1[a]&&G[a][b]!=2) ok=0;
                if(odw1[b]==odw1[a]&&G[a][b]!=1) ok=0;
            }
        }
        if(sz(cycle)>1)
        {
            for(int i=0;i<sz(cycle);i++)
            {
                b[cycle[i]][cycle[(i+1)%sz(cycle)]]=1;
                b[cycle[(i+1)%sz(cycle)]][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;
}*/

# 결과 실행 시간 메모리 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 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 11 ms 1884 KB Output is correct
7 Correct 187 ms 26096 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 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 11 ms 1884 KB Output is correct
7 Correct 187 ms 26096 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 340 KB Output is correct
12 Correct 8 ms 1876 KB Output is correct
13 Correct 180 ms 25884 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 1492 KB Output is correct
17 Correct 116 ms 16076 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 45 ms 7688 KB Output is correct
21 Correct 184 ms 25896 KB Output is correct
22 Correct 176 ms 25964 KB Output is correct
23 Correct 196 ms 26028 KB Output is correct
24 Correct 175 ms 25932 KB Output is correct
25 Correct 88 ms 16032 KB Output is correct
26 Correct 84 ms 16012 KB Output is correct
27 Correct 195 ms 25932 KB Output is correct
28 Correct 182 ms 26060 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 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 -
# 결과 실행 시간 메모리 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 47 ms 7700 KB Output is correct
5 Correct 186 ms 25932 KB Output is correct
6 Correct 175 ms 25964 KB Output is correct
7 Correct 200 ms 25996 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 46 ms 7644 KB Output is correct
10 Correct 180 ms 26004 KB Output is correct
11 Correct 183 ms 25888 KB Output is correct
12 Correct 186 ms 26000 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 47 ms 7700 KB Output is correct
17 Correct 182 ms 26000 KB Output is correct
18 Correct 182 ms 25880 KB Output is correct
19 Correct 181 ms 25884 KB Output is correct
20 Correct 176 ms 26024 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 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 11 ms 1884 KB Output is correct
7 Correct 187 ms 26096 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 340 KB Output is correct
12 Correct 8 ms 1876 KB Output is correct
13 Correct 180 ms 25884 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 1492 KB Output is correct
17 Correct 116 ms 16076 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 45 ms 7688 KB Output is correct
21 Correct 184 ms 25896 KB Output is correct
22 Correct 176 ms 25964 KB Output is correct
23 Correct 196 ms 26028 KB Output is correct
24 Correct 175 ms 25932 KB Output is correct
25 Correct 88 ms 16032 KB Output is correct
26 Correct 84 ms 16012 KB Output is correct
27 Correct 195 ms 25932 KB Output is correct
28 Correct 182 ms 26060 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 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 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 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 11 ms 1884 KB Output is correct
7 Correct 187 ms 26096 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 340 KB Output is correct
12 Correct 8 ms 1876 KB Output is correct
13 Correct 180 ms 25884 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 1492 KB Output is correct
17 Correct 116 ms 16076 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 45 ms 7688 KB Output is correct
21 Correct 184 ms 25896 KB Output is correct
22 Correct 176 ms 25964 KB Output is correct
23 Correct 196 ms 26028 KB Output is correct
24 Correct 175 ms 25932 KB Output is correct
25 Correct 88 ms 16032 KB Output is correct
26 Correct 84 ms 16012 KB Output is correct
27 Correct 195 ms 25932 KB Output is correct
28 Correct 182 ms 26060 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 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 -