Submission #779169

# Submission time Handle Problem Language Result Execution time Memory
779169 2023-07-11T08:38:21 Z jasmin Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
183 ms 22120 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;
            }
        }
    }
    
    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";
}*/
# 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 144 ms 22016 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 144 ms 22016 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 152 ms 22028 KB Output is correct
14 Correct 1 ms 228 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 66 ms 12160 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 36 ms 5724 KB Output is correct
21 Correct 145 ms 22028 KB Output is correct
22 Correct 148 ms 21980 KB Output is correct
23 Correct 149 ms 22020 KB Output is correct
24 Correct 147 ms 22076 KB Output is correct
25 Correct 58 ms 12108 KB Output is correct
26 Correct 59 ms 12156 KB Output is correct
27 Correct 183 ms 22016 KB Output is correct
28 Correct 147 ms 22040 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 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 36 ms 5764 KB Output is correct
5 Correct 160 ms 21964 KB Output is correct
6 Correct 148 ms 22032 KB Output is correct
7 Correct 149 ms 21968 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 36 ms 5772 KB Output is correct
10 Correct 169 ms 22036 KB Output is correct
11 Correct 150 ms 22120 KB Output is correct
12 Correct 151 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 5764 KB Output is correct
17 Correct 149 ms 22016 KB Output is correct
18 Correct 163 ms 21948 KB Output is correct
19 Correct 149 ms 22032 KB Output is correct
20 Correct 152 ms 22092 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 144 ms 22016 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 152 ms 22028 KB Output is correct
14 Correct 1 ms 228 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 66 ms 12160 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 36 ms 5724 KB Output is correct
21 Correct 145 ms 22028 KB Output is correct
22 Correct 148 ms 21980 KB Output is correct
23 Correct 149 ms 22020 KB Output is correct
24 Correct 147 ms 22076 KB Output is correct
25 Correct 58 ms 12108 KB Output is correct
26 Correct 59 ms 12156 KB Output is correct
27 Correct 183 ms 22016 KB Output is correct
28 Correct 147 ms 22040 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 1 ms 212 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 0 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 6 ms 1108 KB Output is correct
7 Correct 144 ms 22016 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 152 ms 22028 KB Output is correct
14 Correct 1 ms 228 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 66 ms 12160 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 36 ms 5724 KB Output is correct
21 Correct 145 ms 22028 KB Output is correct
22 Correct 148 ms 21980 KB Output is correct
23 Correct 149 ms 22020 KB Output is correct
24 Correct 147 ms 22076 KB Output is correct
25 Correct 58 ms 12108 KB Output is correct
26 Correct 59 ms 12156 KB Output is correct
27 Correct 183 ms 22016 KB Output is correct
28 Correct 147 ms 22040 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 1 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -