Submission #758910

# Submission time Handle Problem Language Result Execution time Memory
758910 2023-06-15T13:52:03 Z 1bin Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
#include "supertrees.h"

using namespace std;

#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1005;
int par[NMAX], vis[NMAX], p[NMAX][NMAX], a, b;
vector<int> C[NMAX], V, t;
int find(int x){return par[x] == -1 ? x : par[x] = find(par[x]);}

void dfs(int x){
    if(vis[x]) return;
    vis[x] = 1;
    t.emplace_back(x);
    for(int& y : V) if(!vis[y] && p[x][y] == 2) dfs(y);
    return;
}

int construct(vector<vector<int>>p_){
    int n = p_.size(), a, b;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) p[i][j] = p_[i][j];
    vector<vector<int>> E(n, vector<int>(n, 0));
    
    memset(par, -1, sizeof(par));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++){
            if(p[i][j] == 3) return 0;
            a = find(i); b = find(j);
            if(a == b) continue;
            if(p[i][j] == 1){
                par[b] = a; E[i][j] = 1;
            }
        }
    
    
    for(int i = 0; i < n; i++) C[find(i)].emplace_back(i);
    for(int i = 0; i < n; i++)
        if(find(i) == i){
            V.emplace_back(i);
            for(int&x : C[i])
                for(int j = 0; j < n; j++)
                    if(p[x][j] != p[i][j]) return 0;
        }

    
    for(int& x : V)
        if(!vis[x]){
            t.clear();
            dfs(x);
            int sz = t.size();
            if(sz == 1) continue;
            
            for(int i = 0; i < sz; i++){
                a = t[i], b = t[(i + 1) % sz];
                E[a][b] = E[b][a] = 1;
                for(int j = 0; j < sz; j++)
                    if(i != j && p[t[i]][t[j]] != 2) return 0;
            }
        }
    build(E);
    return 1;
}

/*
int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int n;
    cin >> n;
    vector<vector<int>> v (n, vector<int>(n, 0));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) cin >> v[i][j];
    cout << construct(v) << '\n';
    return 0;
}
*/

/*
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1

2
1 0
0 1

2
1 3
3 1

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 340 KB b is not symmetric: b[0][1] (1) != b[1][0] (0)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 340 KB b is not symmetric: b[0][1] (1) != b[1][0] (0)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 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 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB b is not symmetric: b[1][2] (1) != b[2][1] (0)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 340 KB b is not symmetric: b[0][1] (1) != b[1][0] (0)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 340 KB b is not symmetric: b[0][1] (1) != b[1][0] (0)
3 Halted 0 ms 0 KB -