Submission #720654

# Submission time Handle Problem Language Result Execution time Memory
720654 2023-04-08T19:58:01 Z Toxtaq Connecting Supertrees (IOI20_supertrees) C++17
11 / 100
177 ms 22220 KB
#ifndef SUPERTREES_H_INCLUDED
#define SUPERTREES_H_INCLUDED
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
struct DSU{
    vector<int>par;
    vector<vector<int>>parV;
    DSU(int n){
        par.assign(n, -1);
        parV.resize(n);
        for(int i = 0;i < n;++i)parV[i].push_back(i);
    }
    int FindRep(int u){
        if(par[u] < 0)return u;
        return par[u] = FindRep(par[u]);
    }
    void Union(int u, int v){
        u = FindRep(u);
        v = FindRep(v);
        if(u == v)return;
        if(par[u] > par[v])swap(u, v);
        par[u] += par[v];
        par[v] = u;
        for(int i : parV[v]){
            parV[u].push_back(i);
        }
    }
    bool IsConnected(int u, int v){
        u = FindRep(u);
        v = FindRep(v);
        return (u == v);
    }
};
void build(vector<vector<int>>b);
int construct(vector<vector<int>>p){
    int n = p.size();
    vector<vector<int>>ans(n, vector<int>(n));
    DSU dsu1(n);
    for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
            if(i != j && p[i][j])dsu1.Union(i, j);
        }
    }
    vector<bool>chosen(n);
    for(int i = 0;i < n;++i){
        if(chosen[i])continue;
        vector<int>components, ones, twos;
        swap(components, dsu1.parV[dsu1.FindRep(i)]);
        for(int j : components){
            chosen[j] = 1;
            int cnt = 0;
            for(int z = 0;z < n;++z){
                if(p[j][z] == 1){
                    cnt++;
                }
            }
            if(cnt == 1)twos.push_back(j);
            else ones.push_back(j);
        }
//        cout << i << ": \n";
//        cout << "ones: ";
//        for(int j : ones)cout << j << " ";
//        cout << "\ntwos: ";
//        for(int j : twos)cout << j << " ";
//        cout << '\n';
        for(int j = 1;j < ones.size();++j){
            ans[ones[j - 1]][ones[j]] = 1;
            ans[ones[j]][ones[j - 1]] = 1;
        }
        for(int j = 1;j < twos.size();++j){
            ans[twos[j - 1]][twos[j]] = 1;
            ans[twos[j]][twos[j - 1]] = 1;
        }
        if(!ones.size() && (int)twos.size() > 1){
            ans[twos[0]][twos.back()] = ans[twos.back()][twos[0]] = 1;
        }
        else if(ones.size() && (int)twos.size() > 1){
            ans[ones.back()][twos[0]] = 1;
            ans[twos[0]][ones.back()] = 1;
            ans[twos.back()][ones.back()] = 1;
            ans[ones.back()][twos.back()] = 1;
        }
    }
//    for(int i = 0;i < n;++i){
//        for(int j = i + 1;j < n;++j){
//            if(ans[i][j])cout << i << ", " << j << '\n';
//        }
//    }
    build(ans);
    return 1;
}


#endif // SUPERTREES_H_INCLUDED

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:67:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for(int j = 1;j < ones.size();++j){
      |                       ~~^~~~~~~~~~~~~
supertrees.cpp:71:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int j = 1;j < twos.size();++j){
      |                       ~~^~~~~~~~~~~~~
# 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 1 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 8 ms 1108 KB Output is correct
7 Correct 163 ms 22072 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 1 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 8 ms 1108 KB Output is correct
7 Correct 163 ms 22072 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 1 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 158 ms 22060 KB Output is correct
14 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
15 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 Incorrect 0 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 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 41 ms 5680 KB Output is correct
5 Correct 170 ms 22092 KB Output is correct
6 Correct 164 ms 22092 KB Output is correct
7 Correct 168 ms 22024 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 44 ms 5764 KB Output is correct
10 Correct 161 ms 22028 KB Output is correct
11 Correct 159 ms 22024 KB Output is correct
12 Correct 177 ms 22220 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 Incorrect 41 ms 5780 KB Too few ways to get from 0 to 24, should be 2 found 1
17 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 1 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 8 ms 1108 KB Output is correct
7 Correct 163 ms 22072 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 1 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 158 ms 22060 KB Output is correct
14 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
15 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 1 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 8 ms 1108 KB Output is correct
7 Correct 163 ms 22072 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 1 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 158 ms 22060 KB Output is correct
14 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -