답안 #770732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
770732 2023-07-01T20:14:29 Z alexander707070 슈퍼트리 잇기 (IOI20_supertrees) C++14
21 / 100
184 ms 27224 KB
#include<bits/stdc++.h>
#include "supertrees.h"
#define MAXN 1007
using namespace std;
 
int n,k;
vector<int> cycle[MAXN];
vector<int> v[MAXN];
vector< vector<int> > ans;
bool li[MAXN];
 
int dsu[MAXN],sz[MAXN];
 
int root(int x){
    if(dsu[x]==x)return x;
    dsu[x]=root(dsu[x]);
    return dsu[x];
}
 
void add_edge(int x,int y){
    if(x==y)return;
    ans[x][y]=ans[y][x]=1;   
}
 
void connect(int x,int y){
    if(sz[root(x)]<sz[root(y)])swap(x,y);
    sz[root(x)]+=sz[root(y)];
    dsu[root(y)]=root(x);
    add_edge(x,y);
}
 
void dfs(int x){
    li[x]=true;
    cycle[k].push_back(x);
    for(int i=0;i<v[x].size();i++){
        if(!li[v[x][i]])dfs(v[x][i]);
    }
}
 
int construct(vector< vector<int> > p){
    n=p.size();
 
    ans.resize(n);
    for(int i=0;i<n;i++)ans[i].resize(n);
 
    for(int i=0;i<n;i++){
        for(int f=i+1;f<n;f++){
            if(p[i][f]==2){
                v[i].push_back(f);
                v[f].push_back(i);
            }
            if(p[i][f]==3)return 0;
        }
    }
 
    for(int i=0;i<n;i++){
        dsu[i]=i; sz[i]=1;
    }
    
    for(int i=0;i<n;i++){
        if(!li[i]){
            k++; dfs(i);
            for(int f=0;f<cycle[k].size();f++){
                for(int d=f+1;d<cycle[k].size();d++){
                    if(p[cycle[k][f]][cycle[k][d]]!=2)return 0;
                }
            }
 
            sz[k]=int(cycle[k].size());
            for(int f=0;f<cycle[k].size()-1;f++){
                connect(cycle[k][f],cycle[k][(f+1)%int(cycle[k].size())]);
            }
            add_edge(cycle[k].back(),cycle[k][0]);
        }
    }
 
    for(int i=0;i<n;i++){
        for(int f=i+1;f<n;f++){
            if(p[i][f]==1 and root(i)!=root(f)){
                connect(i,f);
            }            
        }
    }
 
    for(int i=0;i<n;i++){
        for(int f=i+1;f<n;f++){
            if(p[i][f]==0 and root(i)==root(f))return 0;
        }
    }
 
    build(ans);
    return 1;
}

Compilation message

supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:63:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             for(int f=0;f<cycle[k].size();f++){
      |                         ~^~~~~~~~~~~~~~~~
supertrees.cpp:64:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |                 for(int d=f+1;d<cycle[k].size();d++){
      |                               ~^~~~~~~~~~~~~~~~
supertrees.cpp:70:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for(int f=0;f<cycle[k].size()-1;f++){
      |                         ~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 6 ms 1236 KB Output is correct
7 Correct 160 ms 24088 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 6 ms 1236 KB Output is correct
7 Correct 160 ms 24088 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 276 KB Output is correct
12 Correct 10 ms 1316 KB Output is correct
13 Correct 172 ms 23980 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 90 ms 14176 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 52 ms 6216 KB Output is correct
21 Correct 154 ms 24056 KB Output is correct
22 Correct 179 ms 23996 KB Output is correct
23 Correct 159 ms 24036 KB Output is correct
24 Correct 172 ms 24028 KB Output is correct
25 Correct 69 ms 14176 KB Output is correct
26 Correct 69 ms 14156 KB Output is correct
27 Correct 159 ms 23984 KB Output is correct
28 Correct 161 ms 24028 KB Output is correct
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 40 ms 6304 KB Output is correct
5 Correct 174 ms 24016 KB Output is correct
6 Correct 169 ms 23984 KB Output is correct
7 Correct 184 ms 24016 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 40 ms 6252 KB Output is correct
10 Correct 156 ms 24620 KB Output is correct
11 Correct 158 ms 24004 KB Output is correct
12 Correct 162 ms 27224 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Incorrect 0 ms 356 KB Answer gives possible 0 while actual possible 1
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 6 ms 1236 KB Output is correct
7 Correct 160 ms 24088 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 276 KB Output is correct
12 Correct 10 ms 1316 KB Output is correct
13 Correct 172 ms 23980 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 90 ms 14176 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 52 ms 6216 KB Output is correct
21 Correct 154 ms 24056 KB Output is correct
22 Correct 179 ms 23996 KB Output is correct
23 Correct 159 ms 24036 KB Output is correct
24 Correct 172 ms 24028 KB Output is correct
25 Correct 69 ms 14176 KB Output is correct
26 Correct 69 ms 14156 KB Output is correct
27 Correct 159 ms 23984 KB Output is correct
28 Correct 161 ms 24028 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Incorrect 1 ms 340 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 6 ms 1236 KB Output is correct
7 Correct 160 ms 24088 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 276 KB Output is correct
12 Correct 10 ms 1316 KB Output is correct
13 Correct 172 ms 23980 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 90 ms 14176 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 52 ms 6216 KB Output is correct
21 Correct 154 ms 24056 KB Output is correct
22 Correct 179 ms 23996 KB Output is correct
23 Correct 159 ms 24036 KB Output is correct
24 Correct 172 ms 24028 KB Output is correct
25 Correct 69 ms 14176 KB Output is correct
26 Correct 69 ms 14156 KB Output is correct
27 Correct 159 ms 23984 KB Output is correct
28 Correct 161 ms 24028 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Incorrect 1 ms 340 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -