답안 #858169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
858169 2023-10-07T14:24:09 Z _uros9 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
215 ms 24404 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

int n;
int N=1e3+9;
vector<int> rnk(N,0),par(N),rnk1(N,0),par1(N);
int ulp(int node){
    if(par[node]==node) return node;
    return par[node]=ulp(par[node]);
}
void spajaj(int a,int b){
    a=ulp(a);b=ulp(b);
    if(a==b) return;
    if(rnk[b]>rnk[a])
        swap(a,b);
    par[b]=a;
    if(rnk[a]==rnk[b])
        rnk[a]++;
}
int ulp1(int node){
    if(par1[node]==node) return node;
    return par1[node]=ulp1(par1[node]);
}
void spajaj1(int a,int b){
    a=ulp1(a);b=ulp1(b);
    if(a==b) return;
    if(rnk1[b]>rnk1[a])
        swap(a,b);
    par1[b]=a;
    if(rnk1[a]==rnk1[b])
        rnk1[a]++;
}

int construct(std::vector<std::vector<int>> p){
	n=p.size();
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	vector<set<int>> lanci(n);
	for(int i=0; i<n; i++) par[i]=i;
	for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(p[i][j]==1)
                spajaj(i,j);
            if(p[i][j]==3) return 0;
        }
	}
	for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(p[i][j]==1){
                lanci[ulp(i)].insert(j);
                lanci[ulp(i)].insert(i);
            }
            if(ulp(i)==ulp(j)&&p[i][j]!=1)
                return 0;
        }
	}
	for(int i=0; i<n; i++){
        if(lanci[i].size()<=1) continue;
        for(auto it=next(lanci[i].begin()); it!=lanci[i].end(); it++){
            answer[*prev(it)][*it]=1;
            answer[*it][*prev(it)]=1;
        }
	}
	for(int i=0; i<n; i++) par1[ulp(i)]=ulp(i);
	for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(p[i][j]==2)
                spajaj1(ulp(i),ulp(j));
        }
	}
	vector<set<int>> adj(n);
	for(int i=0; i<n; i++)
        adj[ulp1(ulp(i))].insert(ulp(i));
	for(int i=0; i<n; i++){
        if(adj[i].size()<=2) continue;
        for(auto it=next(adj[i].begin()); it!=adj[i].end(); it++){
            answer[*prev(it)][*it]=1;
            answer[*it][*prev(it)]=1;
        }
        answer[*prev(adj[i].end())][*adj[i].begin()]=1;
        answer[*adj[i].begin()][*prev(adj[i].end())]=1;
	}
	for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(p[i][j]==0){
                if(ulp(i)==ulp(j)) return 0;
                if(ulp1(ulp(i))==ulp1(ulp(j))) return 0;
            }
            if(p[i][j]==1)
                if(ulp(i)!=ulp(j)) return 0;
            if(p[i][j]==2){
                if(ulp(i)==ulp(j)) return 0;
                if(ulp1(ulp(i))!=ulp1(ulp(j))) return 0;
            }
        }
	}
	build(answer);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 9 ms 1300 KB Output is correct
7 Correct 215 ms 23296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 9 ms 1300 KB Output is correct
7 Correct 215 ms 23296 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 9 ms 1444 KB Output is correct
13 Correct 171 ms 23376 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 74 ms 13336 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 548 KB Output is correct
20 Correct 53 ms 6484 KB Output is correct
21 Correct 176 ms 24148 KB Output is correct
22 Correct 180 ms 24404 KB Output is correct
23 Correct 207 ms 24148 KB Output is correct
24 Correct 175 ms 24296 KB Output is correct
25 Correct 62 ms 14164 KB Output is correct
26 Correct 70 ms 14232 KB Output is correct
27 Correct 207 ms 24180 KB Output is correct
28 Correct 170 ms 24196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 44 ms 6288 KB Output is correct
5 Correct 178 ms 24292 KB Output is correct
6 Correct 172 ms 24220 KB Output is correct
7 Correct 207 ms 24144 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 45 ms 6396 KB Output is correct
10 Correct 179 ms 24160 KB Output is correct
11 Correct 180 ms 24332 KB Output is correct
12 Correct 190 ms 24344 KB Output is correct
13 Correct 1 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 49 ms 6484 KB Output is correct
17 Correct 172 ms 24144 KB Output is correct
18 Correct 179 ms 24144 KB Output is correct
19 Correct 179 ms 24320 KB Output is correct
20 Correct 168 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 9 ms 1300 KB Output is correct
7 Correct 215 ms 23296 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 9 ms 1444 KB Output is correct
13 Correct 171 ms 23376 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 74 ms 13336 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 548 KB Output is correct
20 Correct 53 ms 6484 KB Output is correct
21 Correct 176 ms 24148 KB Output is correct
22 Correct 180 ms 24404 KB Output is correct
23 Correct 207 ms 24148 KB Output is correct
24 Correct 175 ms 24296 KB Output is correct
25 Correct 62 ms 14164 KB Output is correct
26 Correct 70 ms 14232 KB Output is correct
27 Correct 207 ms 24180 KB Output is correct
28 Correct 170 ms 24196 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 9 ms 1300 KB Output is correct
7 Correct 215 ms 23296 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 9 ms 1444 KB Output is correct
13 Correct 171 ms 23376 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 74 ms 13336 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 548 KB Output is correct
20 Correct 53 ms 6484 KB Output is correct
21 Correct 176 ms 24148 KB Output is correct
22 Correct 180 ms 24404 KB Output is correct
23 Correct 207 ms 24148 KB Output is correct
24 Correct 175 ms 24296 KB Output is correct
25 Correct 62 ms 14164 KB Output is correct
26 Correct 70 ms 14232 KB Output is correct
27 Correct 207 ms 24180 KB Output is correct
28 Correct 170 ms 24196 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -