답안 #653335

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
653335 2022-10-26T14:54:43 Z ansgar 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
203 ms 27788 KB
#include <bits/stdc++.h>
using namespace std;
#include "supertrees.h"
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vb vector<bool>
#define vc vector<char>
#define vvc vector<vc>
#define vvb vector<vb>
#define si set<int>
#define mii map<int,int>

const int mod=1e9+7;
const int N=2e5+1;

int fact[N],frev[N],s[N],l[N];
bool P[N];
vi primes;
vvi G;
vb B;

int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int mcm(int a,int b){
    return (a*b)/gcd(a,b);
}
int poW(int a,int p){
    if(p==0)return 1;
    if(p==1)return a;
    return poW(a*a%mod,p/2)*(p%2?a:1)%mod;
}
bool prime(int n){
    if(n<=1)return false;
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
void initfact(){
    fact[0]=fact[1]=frev[0]=frev[1]=1;
    for(int i=2;i<N;i++){
        fact[i]=i*fact[i-1]%mod;
        frev[i]=poW(fact[i],mod-2);
    }
}
int choose(int n,int k){
    if(n<k)return 0;
    return (fact[n]*frev[k]%mod)*frev[n-k]%mod;
}
void initPrimes(){
    memset(P,true,sizeof(P));
    P[0]=P[1]=false;
    for(int i=2;i<N;i++){
        if(P[i]){
            primes.push_back(i);
            for(int j=i*2;j<N;j+=i){
                P[j]=false;
            }
        }
    }
}
void resetdsu(){
    for(int i=0;i<N;i++){
        s[i]=1;
        l[i]=i;
    }
}
int find(int x){
    while(x!=l[x])x=l[x];
    return x;
}
bool same(int a,int b){
    return find(a)==find(b);
}
void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(s[a]<s[b])swap(a,b);
    l[b]=a;
    s[a]+=s[b];
}
vi obj;
vvi G2;
void dfs(int u){
    B[u]=true;
    obj.push_back(u);
    for(int v : G[u]){
        if(!B[v]){
            dfs(v);
        }
    }
}
void dfs2(int u){
    B[u]=true;
    obj.push_back(u);
    for(int v : G2[u]){
        if(!B[v])dfs2(v);
    }
}
//void build(vvi a){}
int construct(vvi p){
    int n=p.size();
    G=vvi(n);
    resetdsu();
    G2=vvi (n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(p[i][j]==3)return 0;
            if(p[i][j]==1){
                G[i].push_back(j);
                if(!same(i,j)){
                    unite(i,j);
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(p[i][j]==2){
                G2[find(i)].push_back(find(j));
            }
        }
    }
    vvi b(n,vi(n,0));
    B=vb(n,false);
    for(int i=0;i<n;i++){
        obj.clear();
        if(!B[i])dfs(i);
        else continue;
        if(obj.size()==1)continue;
        int x=obj[0];
        for(int i=1;i<(int)obj.size();i++){
            b[x][obj[i]]=b[obj[i]][x]=1;
        }
        for(int i=0;i<(int)obj.size();i++){
            for(int j=0;j<(int)obj.size();j++){
                if(p[obj[i]][obj[j]]!=1)return 0;
            }
        }
    }
    B=vb(n,false);
    for(int i=0;i<n;i++){
        obj.clear();
        if(!B[i])dfs2(i);
        else continue;
        if(obj.size()==2)return 0;
        if(obj.size()==1)continue;
        for(int i=0;i<(int)obj.size();i++){obj[i]=find(obj[i]);}
        b[obj[(int)obj.size()-1]][obj[0]]=b[obj[0]][obj[(int)obj.size()-1]]=1;
        for(int i=1;i<(int)obj.size();i++){
            b[obj[i]][obj[i-1]]=b[obj[i-1]][obj[i]]=1;
        }
        for(int i=0;i<(int)obj.size();i++){
            for(int j=0;j<(int)obj.size();j++){
                if(p[obj[i]][obj[j]]==0)return 0;
            }
        }
    }
    build(b);
    return 1;
}
//signed main(){}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1748 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 9 ms 2900 KB Output is correct
7 Correct 171 ms 27672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1748 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 9 ms 2900 KB Output is correct
7 Correct 171 ms 27672 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 8 ms 2772 KB Output is correct
13 Correct 167 ms 23672 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 6 ms 2388 KB Output is correct
17 Correct 97 ms 16264 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 45 ms 7372 KB Output is correct
21 Correct 173 ms 24232 KB Output is correct
22 Correct 172 ms 23692 KB Output is correct
23 Correct 203 ms 25608 KB Output is correct
24 Correct 167 ms 23616 KB Output is correct
25 Correct 75 ms 14236 KB Output is correct
26 Correct 74 ms 13720 KB Output is correct
27 Correct 179 ms 26632 KB Output is correct
28 Correct 183 ms 23672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1748 KB Output is correct
4 Correct 1 ms 1748 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 8 ms 2772 KB Output is correct
9 Correct 171 ms 23680 KB Output is correct
10 Correct 1 ms 1748 KB Output is correct
11 Correct 1 ms 1748 KB Output is correct
12 Correct 8 ms 2900 KB Output is correct
13 Correct 175 ms 27788 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 5 ms 2388 KB Output is correct
17 Correct 88 ms 16332 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1748 KB Output is correct
21 Correct 44 ms 7356 KB Output is correct
22 Correct 170 ms 24200 KB Output is correct
23 Correct 166 ms 23704 KB Output is correct
24 Correct 176 ms 26752 KB Output is correct
25 Correct 74 ms 13712 KB Output is correct
26 Correct 76 ms 14220 KB Output is correct
27 Correct 163 ms 23708 KB Output is correct
28 Correct 179 ms 25676 KB Output is correct
29 Correct 72 ms 13716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1748 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 44 ms 7312 KB Output is correct
5 Correct 169 ms 24220 KB Output is correct
6 Correct 164 ms 23628 KB Output is correct
7 Correct 184 ms 25628 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 44 ms 7372 KB Output is correct
10 Correct 175 ms 24204 KB Output is correct
11 Correct 164 ms 23692 KB Output is correct
12 Correct 181 ms 26764 KB Output is correct
13 Correct 1 ms 1748 KB Output is correct
14 Correct 1 ms 1748 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 43 ms 7372 KB Output is correct
17 Correct 169 ms 24216 KB Output is correct
18 Correct 171 ms 24140 KB Output is correct
19 Correct 167 ms 23820 KB Output is correct
20 Correct 173 ms 23700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1748 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 9 ms 2900 KB Output is correct
7 Correct 171 ms 27672 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 8 ms 2772 KB Output is correct
13 Correct 167 ms 23672 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 6 ms 2388 KB Output is correct
17 Correct 97 ms 16264 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 45 ms 7372 KB Output is correct
21 Correct 173 ms 24232 KB Output is correct
22 Correct 172 ms 23692 KB Output is correct
23 Correct 203 ms 25608 KB Output is correct
24 Correct 167 ms 23616 KB Output is correct
25 Correct 75 ms 14236 KB Output is correct
26 Correct 74 ms 13720 KB Output is correct
27 Correct 179 ms 26632 KB Output is correct
28 Correct 183 ms 23672 KB Output is correct
29 Correct 1 ms 1876 KB Output is correct
30 Correct 1 ms 1876 KB Output is correct
31 Correct 1 ms 1748 KB Output is correct
32 Correct 1 ms 1748 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct
34 Correct 1 ms 1876 KB Output is correct
35 Correct 1 ms 1876 KB Output is correct
36 Correct 8 ms 2772 KB Output is correct
37 Correct 171 ms 23680 KB Output is correct
38 Correct 1 ms 1748 KB Output is correct
39 Correct 1 ms 1748 KB Output is correct
40 Correct 8 ms 2900 KB Output is correct
41 Correct 175 ms 27788 KB Output is correct
42 Correct 1 ms 1876 KB Output is correct
43 Correct 1 ms 1876 KB Output is correct
44 Correct 5 ms 2388 KB Output is correct
45 Correct 88 ms 16332 KB Output is correct
46 Correct 1 ms 1876 KB Output is correct
47 Correct 1 ms 1876 KB Output is correct
48 Correct 1 ms 1748 KB Output is correct
49 Correct 44 ms 7356 KB Output is correct
50 Correct 170 ms 24200 KB Output is correct
51 Correct 166 ms 23704 KB Output is correct
52 Correct 176 ms 26752 KB Output is correct
53 Correct 74 ms 13712 KB Output is correct
54 Correct 76 ms 14220 KB Output is correct
55 Correct 163 ms 23708 KB Output is correct
56 Correct 179 ms 25676 KB Output is correct
57 Correct 72 ms 13716 KB Output is correct
58 Correct 1 ms 1876 KB Output is correct
59 Correct 1 ms 1876 KB Output is correct
60 Correct 5 ms 2516 KB Output is correct
61 Correct 93 ms 17164 KB Output is correct
62 Correct 1 ms 1876 KB Output is correct
63 Correct 1 ms 1760 KB Output is correct
64 Correct 2 ms 1748 KB Output is correct
65 Correct 46 ms 7288 KB Output is correct
66 Correct 77 ms 14360 KB Output is correct
67 Correct 104 ms 14296 KB Output is correct
68 Correct 74 ms 13976 KB Output is correct
69 Correct 71 ms 13708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1748 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 9 ms 2900 KB Output is correct
7 Correct 171 ms 27672 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 8 ms 2772 KB Output is correct
13 Correct 167 ms 23672 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 6 ms 2388 KB Output is correct
17 Correct 97 ms 16264 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 45 ms 7372 KB Output is correct
21 Correct 173 ms 24232 KB Output is correct
22 Correct 172 ms 23692 KB Output is correct
23 Correct 203 ms 25608 KB Output is correct
24 Correct 167 ms 23616 KB Output is correct
25 Correct 75 ms 14236 KB Output is correct
26 Correct 74 ms 13720 KB Output is correct
27 Correct 179 ms 26632 KB Output is correct
28 Correct 183 ms 23672 KB Output is correct
29 Correct 1 ms 1876 KB Output is correct
30 Correct 1 ms 1876 KB Output is correct
31 Correct 1 ms 1748 KB Output is correct
32 Correct 1 ms 1748 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct
34 Correct 1 ms 1876 KB Output is correct
35 Correct 1 ms 1876 KB Output is correct
36 Correct 8 ms 2772 KB Output is correct
37 Correct 171 ms 23680 KB Output is correct
38 Correct 1 ms 1748 KB Output is correct
39 Correct 1 ms 1748 KB Output is correct
40 Correct 8 ms 2900 KB Output is correct
41 Correct 175 ms 27788 KB Output is correct
42 Correct 1 ms 1876 KB Output is correct
43 Correct 1 ms 1876 KB Output is correct
44 Correct 5 ms 2388 KB Output is correct
45 Correct 88 ms 16332 KB Output is correct
46 Correct 1 ms 1876 KB Output is correct
47 Correct 1 ms 1876 KB Output is correct
48 Correct 1 ms 1748 KB Output is correct
49 Correct 44 ms 7356 KB Output is correct
50 Correct 170 ms 24200 KB Output is correct
51 Correct 166 ms 23704 KB Output is correct
52 Correct 176 ms 26752 KB Output is correct
53 Correct 74 ms 13712 KB Output is correct
54 Correct 76 ms 14220 KB Output is correct
55 Correct 163 ms 23708 KB Output is correct
56 Correct 179 ms 25676 KB Output is correct
57 Correct 72 ms 13716 KB Output is correct
58 Correct 1 ms 1876 KB Output is correct
59 Correct 1 ms 1748 KB Output is correct
60 Correct 1 ms 1876 KB Output is correct
61 Correct 44 ms 7312 KB Output is correct
62 Correct 169 ms 24220 KB Output is correct
63 Correct 164 ms 23628 KB Output is correct
64 Correct 184 ms 25628 KB Output is correct
65 Correct 1 ms 1876 KB Output is correct
66 Correct 44 ms 7372 KB Output is correct
67 Correct 175 ms 24204 KB Output is correct
68 Correct 164 ms 23692 KB Output is correct
69 Correct 181 ms 26764 KB Output is correct
70 Correct 1 ms 1748 KB Output is correct
71 Correct 1 ms 1748 KB Output is correct
72 Correct 1 ms 1876 KB Output is correct
73 Correct 43 ms 7372 KB Output is correct
74 Correct 169 ms 24216 KB Output is correct
75 Correct 171 ms 24140 KB Output is correct
76 Correct 167 ms 23820 KB Output is correct
77 Correct 173 ms 23700 KB Output is correct
78 Correct 1 ms 1876 KB Output is correct
79 Correct 1 ms 1876 KB Output is correct
80 Correct 5 ms 2516 KB Output is correct
81 Correct 93 ms 17164 KB Output is correct
82 Correct 1 ms 1876 KB Output is correct
83 Correct 1 ms 1760 KB Output is correct
84 Correct 2 ms 1748 KB Output is correct
85 Correct 46 ms 7288 KB Output is correct
86 Correct 77 ms 14360 KB Output is correct
87 Correct 104 ms 14296 KB Output is correct
88 Correct 74 ms 13976 KB Output is correct
89 Correct 71 ms 13708 KB Output is correct
90 Correct 1 ms 1876 KB Output is correct
91 Correct 1 ms 1748 KB Output is correct
92 Correct 4 ms 2132 KB Output is correct
93 Correct 72 ms 9676 KB Output is correct
94 Correct 1 ms 1748 KB Output is correct
95 Correct 1 ms 1848 KB Output is correct
96 Correct 1 ms 1844 KB Output is correct
97 Correct 18 ms 4436 KB Output is correct
98 Correct 72 ms 11652 KB Output is correct
99 Correct 73 ms 11648 KB Output is correct
100 Correct 75 ms 11644 KB Output is correct
101 Correct 68 ms 11656 KB Output is correct
102 Correct 72 ms 11708 KB Output is correct
103 Correct 72 ms 11656 KB Output is correct
104 Correct 74 ms 11692 KB Output is correct
105 Correct 78 ms 11648 KB Output is correct