답안 #964044

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964044 2024-04-16T08:52:59 Z SuPythony 슈퍼트리 잇기 (IOI20_supertrees) C++17
11 / 100
164 ms 24224 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

class DSU {
    vector<int> par;
    vector<int> siz;

public:
    DSU(int n) {
        par.resize(n);
        iota(par.begin(),par.end(),0);
        siz.assign(n,1);
    }

    int find_set(int u) {
        if (par[u]==u) return u;
        return par[u]=find_set(par[u]);
    }

    bool is_same(int u, int v) {
        return find_set(u)==find_set(v);
    }

    bool unite_set(int u, int v) {
        u=find_set(u);
        v=find_set(v);
        if (u==v) return false;
        if (siz[u]<siz[v]) swap(u,v);
        par[v]=u;
        siz[u]+=siz[v];
        return true;
    }
};

int construct(vector<vector<int>> p) {
    int n = p.size();
    vector<vector<int>> ans(n,vector<int>(n,0));
    DSU dsu1=DSU(n);
    DSU dsu2=DSU(n);
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            if (i==j) continue;
            if (p[i][j]==1) {
                if (dsu1.unite_set(i,j)) {
                    ans[i][j]=1;
                    ans[j][i]=1;
                }
            }
            if (p[i][j]==2) {
                dsu2.unite_set(i,j);
            }
        }
    }
//    for (int i=0; i<n; i++) {
//        for (int j=0; j<n; j++) {
//            if (p[i][j]==0&&(dsu1.is_same(i,j)||dsu2.is_same(i,j))) {
//                return 0;
//            }
//            if (p[i][j]==1) {
//                if (dsu2.is_same(i,j)) return 0;
//            }
//            if (p[i][j]==2) {
//                if (dsu1.is_same(i,j)) return 0;
//            }
//        }
//    }
    unordered_map<int,vector<int>> m;
    for (int i=0; i<n; i++) {
        int s=dsu2.find_set(i);
        bool found=false;
        for (int j=0; j<n; j++) {
            if (i==j) continue;
            if (p[i][j]==1&&dsu2.find_set(j)==s) {
                p[i][j]=45445;
                p[j][i]=46556;
                found=true;
                break;
            }
        }
        if (found) continue;
        m[s].push_back(i);
    }
    for (auto i: m) {
        vector<int> v=i.second;
        if (v.size()==1||v.size()==0) continue;
        if (v.size()==2) return 0;
        ans[v.front()][v.back()]=1;
        ans[v.back()][v.front()]=1;
        for (int j=0; j<v.size()-1; j++) {
            ans[v[j]][v[j+1]]=1;
            ans[v[j+1]][v[j]]=1;
        }
    }
//    for (auto i: ans) {
//        for (int j: i) cout<<j<<" ";
//        cout<<"\n";
//    }
    build(ans);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:90:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |         for (int j=0; j<v.size()-1; j++) {
      |                       ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 157 ms 24048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 157 ms 24048 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1624 KB Output is correct
13 Correct 153 ms 24184 KB Output is correct
14 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 6 ms 1116 KB Output is correct
9 Correct 155 ms 22260 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1264 KB Output is correct
13 Correct 156 ms 22012 KB Output is correct
14 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 39 ms 6360 KB Output is correct
5 Correct 155 ms 24224 KB Output is correct
6 Correct 156 ms 24112 KB Output is correct
7 Correct 161 ms 24068 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 40 ms 6244 KB Output is correct
10 Correct 154 ms 24124 KB Output is correct
11 Correct 164 ms 24052 KB Output is correct
12 Correct 159 ms 23936 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Incorrect 22 ms 3928 KB Answer gives possible 0 while actual possible 1
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 157 ms 24048 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1624 KB Output is correct
13 Correct 153 ms 24184 KB Output is correct
14 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 157 ms 24048 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1624 KB Output is correct
13 Correct 153 ms 24184 KB Output is correct
14 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -