답안 #747148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747148 2023-05-23T17:26:44 Z Rafi22 슈퍼트리 잇기 (IOI20_supertrees) C++14
56 / 100
210 ms 27968 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)%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 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 2004 KB Output is correct
7 Correct 205 ms 26208 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 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 2004 KB Output is correct
7 Correct 205 ms 26208 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 9 ms 2004 KB Output is correct
13 Correct 174 ms 26184 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 1504 KB Output is correct
17 Correct 95 ms 16156 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 7768 KB Output is correct
21 Correct 210 ms 26084 KB Output is correct
22 Correct 172 ms 26036 KB Output is correct
23 Correct 190 ms 26192 KB Output is correct
24 Correct 178 ms 26008 KB Output is correct
25 Correct 79 ms 16308 KB Output is correct
26 Correct 83 ms 16324 KB Output is correct
27 Correct 191 ms 26032 KB Output is correct
28 Correct 192 ms 26076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 46 ms 7752 KB Output is correct
5 Correct 178 ms 26104 KB Output is correct
6 Correct 174 ms 26036 KB Output is correct
7 Correct 210 ms 26256 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 45 ms 7780 KB Output is correct
10 Correct 178 ms 27856 KB Output is correct
11 Correct 184 ms 27884 KB Output is correct
12 Correct 186 ms 27916 KB Output is correct
13 Correct 1 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 44 ms 8140 KB Output is correct
17 Correct 189 ms 27916 KB Output is correct
18 Correct 174 ms 27968 KB Output is correct
19 Correct 195 ms 27940 KB Output is correct
20 Correct 165 ms 27868 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 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 2004 KB Output is correct
7 Correct 205 ms 26208 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 9 ms 2004 KB Output is correct
13 Correct 174 ms 26184 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 1504 KB Output is correct
17 Correct 95 ms 16156 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 7768 KB Output is correct
21 Correct 210 ms 26084 KB Output is correct
22 Correct 172 ms 26036 KB Output is correct
23 Correct 190 ms 26192 KB Output is correct
24 Correct 178 ms 26008 KB Output is correct
25 Correct 79 ms 16308 KB Output is correct
26 Correct 83 ms 16324 KB Output is correct
27 Correct 191 ms 26032 KB Output is correct
28 Correct 192 ms 26076 KB Output is correct
29 Correct 1 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 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 2004 KB Output is correct
7 Correct 205 ms 26208 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 9 ms 2004 KB Output is correct
13 Correct 174 ms 26184 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 1504 KB Output is correct
17 Correct 95 ms 16156 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 7768 KB Output is correct
21 Correct 210 ms 26084 KB Output is correct
22 Correct 172 ms 26036 KB Output is correct
23 Correct 190 ms 26192 KB Output is correct
24 Correct 178 ms 26008 KB Output is correct
25 Correct 79 ms 16308 KB Output is correct
26 Correct 83 ms 16324 KB Output is correct
27 Correct 191 ms 26032 KB Output is correct
28 Correct 192 ms 26076 KB Output is correct
29 Correct 1 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 1 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -