답안 #779176

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779176 2023-07-11T08:41:53 Z jasmin 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
186 ms 22164 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;

/*void build(vector<vector<int> > adi){
        int n=adi.size();
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                cout << adi[i][j] << " ";
            }
            cout << "\n";
        }
}*/

vector<vector<int> > components(vector<vector<int> >& p, int n, bool& pos){
    vector<vector<int> > comp;

    vector<bool> vis(n);
    for(int v=0; v<n; v++){
        if(vis[v]) continue;
        vis[v]=true;

        comp.push_back({});
        comp.back().push_back(v);
        for(int u=0; u<n; u++){
            if(u!=v && p[v][u]!=0){

                comp.back().push_back(u);
                if(vis[u] || p[u][v]==0) pos=false;
                vis[u]=true;
            }
            else if(u!=v){
                if(p[u][v]!=0) pos=false;
            }
        }
    }
    
    return comp;
}

void solve_component(vector<int>& c, int n, vector<vector<int> >& p, vector<vector<int> >& adi, bool& pos){

    vector<int> cycle;
    vector<bool> vis(n);
    for(auto v: c){
        if(vis[v]) continue;

        cycle.push_back(v);
        for(auto u: c){

            if(u!=v && p[v][u]==1){
                adi[v][u]=1;
                adi[u][v]=1;

                vis[u]=true;

                for(int i=0; i<n; i++){
                    pos = pos && (p[v][i] == p[u][i]);
                }
            }
        }
    }

    for(int i=0; i+1<(int)cycle.size(); i++){
        adi[cycle[i]][cycle[i+1]]=1;
        adi[cycle[i+1]][cycle[i]]=1;
    }
    if(cycle.size()>1){
        adi[cycle[0]][cycle.back()]=1;
        adi[cycle.back()][cycle[0]]=1;
    }
}

int construct(vector<vector<int> > p) {
	int n = p.size();
	
    bool pos=true;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(p[i][j]==3){
                pos=false;
            }
        }
    }
	
	vector<vector<int> > comp=components(p, n, pos);

    /*cout << "components\n";
    for(auto e: comp){
        for(auto x: e) cout << x << " ";
        cout << "\n";
    }*/

    vector<vector<int> > adi(n, vector<int> (n, 0));
    for(auto c: comp){
        solve_component(c, n, p, adi, pos);
    }

    if(pos){
        build(adi);
        return 1;
    }
    return 0;
}

/*signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<vector<int> > p(n, vector<int> (n));
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin >> p[i][j];
        }
    }

    cout << construct(p) << "\n";
}*/
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1168 KB Output is correct
7 Correct 149 ms 22028 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 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1168 KB Output is correct
7 Correct 149 ms 22028 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 212 KB Output is correct
12 Correct 6 ms 1152 KB Output is correct
13 Correct 146 ms 22028 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 69 ms 12164 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 5740 KB Output is correct
21 Correct 151 ms 22092 KB Output is correct
22 Correct 148 ms 22024 KB Output is correct
23 Correct 153 ms 22020 KB Output is correct
24 Correct 185 ms 22020 KB Output is correct
25 Correct 64 ms 12096 KB Output is correct
26 Correct 62 ms 12160 KB Output is correct
27 Correct 158 ms 21984 KB Output is correct
28 Correct 150 ms 22036 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 1 ms 212 KB Output is correct
4 Incorrect 1 ms 256 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 38 ms 5752 KB Output is correct
5 Correct 152 ms 22020 KB Output is correct
6 Correct 173 ms 22140 KB Output is correct
7 Correct 152 ms 22024 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 39 ms 5772 KB Output is correct
10 Correct 154 ms 22020 KB Output is correct
11 Correct 150 ms 22024 KB Output is correct
12 Correct 172 ms 21952 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 38 ms 5668 KB Output is correct
17 Correct 151 ms 22004 KB Output is correct
18 Correct 152 ms 22164 KB Output is correct
19 Correct 147 ms 21956 KB Output is correct
20 Correct 186 ms 22064 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 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1168 KB Output is correct
7 Correct 149 ms 22028 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 212 KB Output is correct
12 Correct 6 ms 1152 KB Output is correct
13 Correct 146 ms 22028 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 69 ms 12164 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 5740 KB Output is correct
21 Correct 151 ms 22092 KB Output is correct
22 Correct 148 ms 22024 KB Output is correct
23 Correct 153 ms 22020 KB Output is correct
24 Correct 185 ms 22020 KB Output is correct
25 Correct 64 ms 12096 KB Output is correct
26 Correct 62 ms 12160 KB Output is correct
27 Correct 158 ms 21984 KB Output is correct
28 Correct 150 ms 22036 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 1 ms 256 KB Answer gives possible 1 while actual possible 0
33 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1168 KB Output is correct
7 Correct 149 ms 22028 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 212 KB Output is correct
12 Correct 6 ms 1152 KB Output is correct
13 Correct 146 ms 22028 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 69 ms 12164 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 5740 KB Output is correct
21 Correct 151 ms 22092 KB Output is correct
22 Correct 148 ms 22024 KB Output is correct
23 Correct 153 ms 22020 KB Output is correct
24 Correct 185 ms 22020 KB Output is correct
25 Correct 64 ms 12096 KB Output is correct
26 Correct 62 ms 12160 KB Output is correct
27 Correct 158 ms 21984 KB Output is correct
28 Correct 150 ms 22036 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 1 ms 256 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -