Submission #779182

# Submission time Handle Problem Language Result Execution time Memory
779182 2023-07-11T08:45:11 Z jasmin Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
163 ms 22132 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;
    }

    if(cycle.size()==2){
        pos=false;
    }
}

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";
}*/
# 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 153 ms 22132 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 153 ms 22132 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 7 ms 1160 KB Output is correct
13 Correct 151 ms 22100 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 65 ms 12164 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 37 ms 5672 KB Output is correct
21 Correct 152 ms 21964 KB Output is correct
22 Correct 152 ms 21952 KB Output is correct
23 Correct 154 ms 22020 KB Output is correct
24 Correct 151 ms 22088 KB Output is correct
25 Correct 60 ms 12048 KB Output is correct
26 Correct 60 ms 12096 KB Output is correct
27 Correct 154 ms 21928 KB Output is correct
28 Correct 153 ms 22132 KB Output is correct
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1108 KB Output is correct
9 Correct 158 ms 22020 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 151 ms 22024 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 716 KB Output is correct
17 Correct 69 ms 12160 KB Output is correct
18 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 5748 KB Output is correct
5 Correct 150 ms 22056 KB Output is correct
6 Correct 151 ms 22032 KB Output is correct
7 Correct 154 ms 22036 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 37 ms 5696 KB Output is correct
10 Correct 150 ms 22020 KB Output is correct
11 Correct 149 ms 21956 KB Output is correct
12 Correct 153 ms 22028 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 38 ms 5776 KB Output is correct
17 Correct 150 ms 22020 KB Output is correct
18 Correct 152 ms 21948 KB Output is correct
19 Correct 163 ms 21984 KB Output is correct
20 Correct 154 ms 22032 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 153 ms 22132 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 7 ms 1160 KB Output is correct
13 Correct 151 ms 22100 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 65 ms 12164 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 37 ms 5672 KB Output is correct
21 Correct 152 ms 21964 KB Output is correct
22 Correct 152 ms 21952 KB Output is correct
23 Correct 154 ms 22020 KB Output is correct
24 Correct 151 ms 22088 KB Output is correct
25 Correct 60 ms 12048 KB Output is correct
26 Correct 60 ms 12096 KB Output is correct
27 Correct 154 ms 21928 KB Output is correct
28 Correct 153 ms 22132 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 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 158 ms 22020 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1108 KB Output is correct
41 Correct 151 ms 22024 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 716 KB Output is correct
45 Correct 69 ms 12160 KB Output is correct
46 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
47 Halted 0 ms 0 KB -
# 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 153 ms 22132 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 7 ms 1160 KB Output is correct
13 Correct 151 ms 22100 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 65 ms 12164 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 37 ms 5672 KB Output is correct
21 Correct 152 ms 21964 KB Output is correct
22 Correct 152 ms 21952 KB Output is correct
23 Correct 154 ms 22020 KB Output is correct
24 Correct 151 ms 22088 KB Output is correct
25 Correct 60 ms 12048 KB Output is correct
26 Correct 60 ms 12096 KB Output is correct
27 Correct 154 ms 21928 KB Output is correct
28 Correct 153 ms 22132 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 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 158 ms 22020 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1108 KB Output is correct
41 Correct 151 ms 22024 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 716 KB Output is correct
45 Correct 69 ms 12160 KB Output is correct
46 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
47 Halted 0 ms 0 KB -