답안 #724069

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
724069 2023-04-14T16:42:22 Z Urvuk3 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
197 ms 24140 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int INF=1e9;
const ll LINF=1e18;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define pb push_back

void PRINT(int x) {cerr << x;}
void PRINT(ll x) {cerr << x;}
void PRINT(double x) {cerr << x;}
void PRINT(char x) {cerr << '\'' << x << '\'';}
void PRINT(string x) {cerr << '\"' << x << '\"';}
void PRINT(bool x) {cerr << (x ? "true" : "false");}

template<typename T,typename V>
void PRINT(pair<T,V>& x){
    cerr<<"{";
    PRINT(x.fi);
    cerr<<",";
    PRINT(x.se);
    cerr<<"}";
}
template<typename T>
void PRINT(T &x){
    int id=0;
    cerr<<"{";
    for(auto _i:x){
        cerr<<(id++ ? "," : "");
        PRINT(_i);
    }
    cerr<<"}";
}
void _PRINT(){
    cerr<<"]\n";
}
template<typename Head,typename... Tail>
void _PRINT(Head h,Tail... t){
    PRINT(h);
    if(sizeof...(t)) cerr<<", ";
    _PRINT(t...);
}

#define Debug(x...) cerr<<"["<<#x<<"]=["; _PRINT(x)

vector<vector<int>> comp;
vector<int> par;

void Connect(int i,int j){
    i=par[i]; j=par[j];
    if(i==j) return;
    if(sz(comp[i])<=sz(comp[j])) swap(i,j);
    for(int x:comp[j]){
        comp[i].pb(x);
        par[x]=i;
    }
    comp[j].clear();
}

int construct(vector<vector<int>> p) {
	int N=sz(p);
	comp.resize(N); par.resize(N);
    for(int i=0;i<N;i++){
        comp[i].pb(i); par[i]=i;
    }
	for(int i=0;i<N;i++){
        for(int j=0;j<i;j++){
            if(p[i][j]==3) return 0;
            if(p[i][j]) Connect(i,j);
        }
	}
	vector<vector<int>> answer(N,vector<int>(N,0));
	vector<bool> vis(N,false);
	for(vector<int> c:comp){
        //Debug(c);
        if(sz(c)==2 && p[c[0]][c[1]]==2) return 0;
        for(int i:c){
            for(int j:c){
                if(p[i][j]==0) return 0;
            }
        }
        vector<int> cycle,tmp;
        for(int u:c){
            if(!vis[u]){
                for(int v:c){
                    if(p[u][v]==1){
                        tmp.pb(v);
                        vis[v]=true;
                    }
                }
                cycle.pb(u);
                for(int i=1;i<sz(tmp);i++){
                    int u=tmp[i],v=tmp[i-1];
                    answer[u][v]=1;
                    answer[v][u]=1;
                }
                //Debug(tmp);
                tmp.clear();
            }
        }
        //Debug(cycle);
        if(sz(cycle)>1){
            for(int i=0;i<sz(cycle);i++){
                if(i==0){
                    int u=cycle[0],v=cycle.back();
                    answer[u][v]=1;
                    answer[v][u]=1;
                }
                else{
                    int u=cycle[i],v=cycle[i-1];
                    answer[u][v]=1;
                    answer[v][u]=1;
                }
            }
        }
	}
	build(answer);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 8 ms 1208 KB Output is correct
7 Correct 183 ms 24052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 8 ms 1208 KB Output is correct
7 Correct 183 ms 24052 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 0 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 171 ms 23984 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 79 ms 14156 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 44 ms 6288 KB Output is correct
21 Correct 188 ms 23980 KB Output is correct
22 Correct 164 ms 24140 KB Output is correct
23 Correct 197 ms 24012 KB Output is correct
24 Correct 181 ms 24048 KB Output is correct
25 Correct 93 ms 14156 KB Output is correct
26 Correct 67 ms 14072 KB Output is correct
27 Correct 180 ms 24048 KB Output is correct
28 Correct 187 ms 24112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 8 ms 1108 KB Output is correct
9 Correct 166 ms 22016 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 168 ms 22160 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 78 ms 12176 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 41 ms 5708 KB Output is correct
22 Correct 174 ms 22052 KB Output is correct
23 Correct 163 ms 22120 KB Output is correct
24 Correct 179 ms 22016 KB Output is correct
25 Correct 90 ms 12160 KB Output is correct
26 Correct 72 ms 12164 KB Output is correct
27 Correct 164 ms 22020 KB Output is correct
28 Correct 193 ms 21996 KB Output is correct
29 Correct 70 ms 12160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 45 ms 5760 KB Output is correct
5 Correct 167 ms 22060 KB Output is correct
6 Correct 173 ms 22016 KB Output is correct
7 Correct 174 ms 24044 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 43 ms 6212 KB Output is correct
10 Correct 171 ms 24056 KB Output is correct
11 Correct 171 ms 24012 KB Output is correct
12 Correct 178 ms 24012 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 42 ms 6348 KB Output is correct
17 Correct 195 ms 24048 KB Output is correct
18 Correct 188 ms 23968 KB Output is correct
19 Correct 170 ms 24008 KB Output is correct
20 Correct 184 ms 24032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 8 ms 1208 KB Output is correct
7 Correct 183 ms 24052 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 0 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 171 ms 23984 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 79 ms 14156 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 44 ms 6288 KB Output is correct
21 Correct 188 ms 23980 KB Output is correct
22 Correct 164 ms 24140 KB Output is correct
23 Correct 197 ms 24012 KB Output is correct
24 Correct 181 ms 24048 KB Output is correct
25 Correct 93 ms 14156 KB Output is correct
26 Correct 67 ms 14072 KB Output is correct
27 Correct 180 ms 24048 KB Output is correct
28 Correct 187 ms 24112 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1108 KB Output is correct
37 Correct 166 ms 22016 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 1108 KB Output is correct
41 Correct 168 ms 22160 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 78 ms 12176 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 41 ms 5708 KB Output is correct
50 Correct 174 ms 22052 KB Output is correct
51 Correct 163 ms 22120 KB Output is correct
52 Correct 179 ms 22016 KB Output is correct
53 Correct 90 ms 12160 KB Output is correct
54 Correct 72 ms 12164 KB Output is correct
55 Correct 164 ms 22020 KB Output is correct
56 Correct 193 ms 21996 KB Output is correct
57 Correct 70 ms 12160 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 4 ms 828 KB Output is correct
61 Correct 76 ms 14072 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 300 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 42 ms 6220 KB Output is correct
66 Correct 84 ms 14064 KB Output is correct
67 Correct 73 ms 14080 KB Output is correct
68 Correct 69 ms 14068 KB Output is correct
69 Correct 65 ms 14080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 8 ms 1208 KB Output is correct
7 Correct 183 ms 24052 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 0 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 171 ms 23984 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 79 ms 14156 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 44 ms 6288 KB Output is correct
21 Correct 188 ms 23980 KB Output is correct
22 Correct 164 ms 24140 KB Output is correct
23 Correct 197 ms 24012 KB Output is correct
24 Correct 181 ms 24048 KB Output is correct
25 Correct 93 ms 14156 KB Output is correct
26 Correct 67 ms 14072 KB Output is correct
27 Correct 180 ms 24048 KB Output is correct
28 Correct 187 ms 24112 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1108 KB Output is correct
37 Correct 166 ms 22016 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 1108 KB Output is correct
41 Correct 168 ms 22160 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 78 ms 12176 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 41 ms 5708 KB Output is correct
50 Correct 174 ms 22052 KB Output is correct
51 Correct 163 ms 22120 KB Output is correct
52 Correct 179 ms 22016 KB Output is correct
53 Correct 90 ms 12160 KB Output is correct
54 Correct 72 ms 12164 KB Output is correct
55 Correct 164 ms 22020 KB Output is correct
56 Correct 193 ms 21996 KB Output is correct
57 Correct 70 ms 12160 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 45 ms 5760 KB Output is correct
62 Correct 167 ms 22060 KB Output is correct
63 Correct 173 ms 22016 KB Output is correct
64 Correct 174 ms 24044 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 43 ms 6212 KB Output is correct
67 Correct 171 ms 24056 KB Output is correct
68 Correct 171 ms 24012 KB Output is correct
69 Correct 178 ms 24012 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 42 ms 6348 KB Output is correct
74 Correct 195 ms 24048 KB Output is correct
75 Correct 188 ms 23968 KB Output is correct
76 Correct 170 ms 24008 KB Output is correct
77 Correct 184 ms 24032 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 4 ms 828 KB Output is correct
81 Correct 76 ms 14072 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 300 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 42 ms 6220 KB Output is correct
86 Correct 84 ms 14064 KB Output is correct
87 Correct 73 ms 14080 KB Output is correct
88 Correct 69 ms 14068 KB Output is correct
89 Correct 65 ms 14080 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 4 ms 596 KB Output is correct
93 Correct 74 ms 10112 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 296 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 19 ms 2772 KB Output is correct
98 Correct 65 ms 10096 KB Output is correct
99 Correct 68 ms 10112 KB Output is correct
100 Correct 67 ms 10096 KB Output is correct
101 Correct 86 ms 10112 KB Output is correct
102 Correct 71 ms 10096 KB Output is correct
103 Correct 71 ms 10100 KB Output is correct
104 Correct 68 ms 10096 KB Output is correct
105 Correct 80 ms 10192 KB Output is correct