답안 #1090026

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090026 2024-09-17T15:18:04 Z onlk97 슈퍼트리 잇기 (IOI20_supertrees) C++14
56 / 100
142 ms 24148 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
struct DSU{
    vector <int> dsu;
    void init(int n){
        dsu.clear();
        for (int i=0; i<=n; i++) dsu.push_back(i);
    }
    int prt(int n){
        if (dsu[n]==n) return n;
        return dsu[n]=prt(dsu[n]);
    }
    void unn(int u,int v){
        dsu[prt(u)]=dsu[prt(v)];
    }
};
int construct(vector <vector <int> > p){
    int n=p.size();
    DSU d;
    d.init(n);
    vector <vector <int> > op(n,vector <int>(n,0));
    for (int i=0; i<n; i++){
        for (int j=i+1; j<n; j++){
            if (p[i][j]==1){
                if (d.prt(i)!=d.prt(j)){
                    d.unn(i,j);
                    op[i][j]=1; op[j][i]=1;
                }
            }
            if (p[i][j]==3) return 0;
        }
    }
    for (int i=0; i<n; i++){
        for (int j=i+1; j<n; j++){
            if ((p[i][j]==1)!=(d.prt(i)==d.prt(j))) return 0;
        }
    }
    for (int i=0; i<n; i++){
        if (p[i]!=p[d.prt(i)]) return 0;
    }
    bool done[n];
    for (int i=0; i<n; i++) done[i]=0;
    for (int i=0; i<n; i++){
        if (d.prt(i)!=i||done[i]) continue;
        set <int> s;
        s.insert(d.prt(i));
        for (int j=i+1; j<n; j++){
            if (p[i][j]==2) s.insert(d.prt(j));
        }
        if (s.size()==1){
            done[i]=1;
            continue;
        }
        if (s.size()<3) return 0;
        vector <int> vec;
        for (int j:s) vec.push_back(j);
        for (int j=0; j<s.size(); j++){
            op[vec[j]][vec[(j+1)%s.size()]]=1; op[vec[(j+1)%s.size()]][vec[j]]=1;
        }
        for (int j:vec){
            done[j]=1;
            for (int k=0; k<n; k++){
                if (p[j][k]==2&&s.find(d.prt(k))==s.end()) return 0;
            }
        }
    }
    build(op);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:59:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for (int j=0; j<s.size(); j++){
      |                       ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1344 KB Output is correct
7 Correct 118 ms 24148 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 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1344 KB Output is correct
7 Correct 118 ms 24148 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 129 ms 24036 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 59 ms 14080 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 6272 KB Output is correct
21 Correct 119 ms 24024 KB Output is correct
22 Correct 123 ms 23972 KB Output is correct
23 Correct 124 ms 24148 KB Output is correct
24 Correct 117 ms 24132 KB Output is correct
25 Correct 52 ms 14208 KB Output is correct
26 Correct 50 ms 14160 KB Output is correct
27 Correct 124 ms 23980 KB Output is correct
28 Correct 120 ms 23940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 432 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1368 KB Output is correct
9 Correct 116 ms 24068 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 6 ms 1372 KB Output is correct
13 Correct 142 ms 23900 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 59 ms 14200 KB Output is correct
18 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
19 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 0 ms 348 KB Output is correct
4 Correct 30 ms 6236 KB Output is correct
5 Correct 135 ms 23944 KB Output is correct
6 Correct 117 ms 24144 KB Output is correct
7 Correct 131 ms 24148 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 31 ms 6400 KB Output is correct
10 Correct 121 ms 24148 KB Output is correct
11 Correct 121 ms 24064 KB Output is correct
12 Correct 135 ms 24084 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 29 ms 6336 KB Output is correct
17 Correct 117 ms 24060 KB Output is correct
18 Correct 114 ms 24144 KB Output is correct
19 Correct 112 ms 23912 KB Output is correct
20 Correct 126 ms 23956 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 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1344 KB Output is correct
7 Correct 118 ms 24148 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 129 ms 24036 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 59 ms 14080 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 6272 KB Output is correct
21 Correct 119 ms 24024 KB Output is correct
22 Correct 123 ms 23972 KB Output is correct
23 Correct 124 ms 24148 KB Output is correct
24 Correct 117 ms 24132 KB Output is correct
25 Correct 52 ms 14208 KB Output is correct
26 Correct 50 ms 14160 KB Output is correct
27 Correct 124 ms 23980 KB Output is correct
28 Correct 120 ms 23940 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 432 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1368 KB Output is correct
37 Correct 116 ms 24068 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 6 ms 1372 KB Output is correct
41 Correct 142 ms 23900 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 59 ms 14200 KB Output is correct
46 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
47 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 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1344 KB Output is correct
7 Correct 118 ms 24148 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 129 ms 24036 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 59 ms 14080 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 6272 KB Output is correct
21 Correct 119 ms 24024 KB Output is correct
22 Correct 123 ms 23972 KB Output is correct
23 Correct 124 ms 24148 KB Output is correct
24 Correct 117 ms 24132 KB Output is correct
25 Correct 52 ms 14208 KB Output is correct
26 Correct 50 ms 14160 KB Output is correct
27 Correct 124 ms 23980 KB Output is correct
28 Correct 120 ms 23940 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 432 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1368 KB Output is correct
37 Correct 116 ms 24068 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 6 ms 1372 KB Output is correct
41 Correct 142 ms 23900 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 59 ms 14200 KB Output is correct
46 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
47 Halted 0 ms 0 KB -