답안 #1076806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1076806 2024-08-26T16:47:18 Z Hectorungo_18 슈퍼트리 잇기 (IOI20_supertrees) C++14
21 / 100
137 ms 24148 KB
#include "supertrees.h"
#include <vector>
#include<bits/stdc++.h>
 
using namespace std;
 
 
 
const int N = 1e3+7;
int p[N];
int sz[N];
 
 
int pa(int u){
	p[u]=(p[u] == u ? u : pa(p[u]));
	return p[u];
}
 
bool sm(int u, int v){
	return pa(u) == pa(v);
}
 
void un(int u, int v){
	if(sm(u, v)) return;
	u = pa(u);
	v = pa(v);
	if(sz[v] > sz[u]) swap(u, v);
	sz[u]+=sz[v];
	p[v]=u;
}
 
int construct(vector<vector<int>> v) {
	int n = v.size();
	for(int i = 0; i <= n; i++){
		p[i]=i;
		sz[i]=1;
	}
	for(int i = 0; i < n; i++){
        bool ch = 0;
        if(pa(i)==i) ch = 1;
		for(int j = i+1; j < n; j++){
			if(ch){
                if(v[i][j] == 0) continue;
                if(pa(j) == j){
                    un(i, j);
                }
                else return 0;
			}
            else{
                if(v[i][j] == 0){
                  if(pa(i) == pa(j)) return 0;
                }
              else if(pa(i) != pa(j)) return 0;
              	
            }
		}
	}
 
    map<int, int> m;
    for(int i = 0; i < n; i++){
        vector<int> a(4, 0);
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            a[v[i][j]]++;
        }
        if(a[1] > 0) m[i]=1;
        else if(a[2] > 0) m[i]=2;
        else if(a[3] > 0) m[i]=3;
        else m[i]=0;
    }
 
    vector<vector<int>> ans(n, vector<int> (n, 0));
    vector<int> sp(n);
    for(int i = 0; i < n; i++){
        sp[i]=pa(i);
    }
    for(int i = 0; i < n; i++){
        p[i]=i;
        sz[i]=i;
    }
    for(int i = 0; i < n; i++){
        if(sp[i] != i) continue;
        vector<int> w;
        for(int j = 0; j < n; j++){
            if(sp[j] == i) w.push_back(j);
        }
        vector<int> dd;
        for(int j = 0; j < w.size(); j++){
            int r = w[j];
 
            for(int k = 0; k < n; k++){
                if(k == r) continue;
                if(v[r][k] != 1) continue;
                if(pa(r) == pa(k)) continue;
                if(pa(r) == r){
                    un(r, k);
                }
                else{
                    if(pa(k) == k){
                        un(r, k);
                    }
                    else return 0;
                }
            }
        }
        for(int j = 0; j < w.size(); j++){
            if(w[j] == pa(w[j])) dd.push_back(j);
        }
        if(dd.size() == 2) return 0;
        for(int j = 1; j < dd.size(); j++){
            ans[dd[j]][dd[j-1]] = 1;
            ans[dd[j-1]][dd[j]] = 1;
        }
        if(dd.size() > 2){
            ans[dd[0]][dd.back()] = 1;
            ans[dd.back()][dd[0]] = 1;
        }
        vector<vector<int>> adj(n);
        for(int i = 0; i < w.size(); i++){
            int r = w[i];
            adj[pa(r)].push_back(r);
        }
        for(int i = 0; i < n; i++){
            for(int j = 1; j < adj[i].size(); j++){
                ans[adj[i][j]][adj[i][j-1]] = 1;
                ans[adj[i][j-1]][adj[i][j]] = 1;
            }
        }
    }
    
    build(ans);
 
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:88:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for(int j = 0; j < w.size(); j++){
      |                        ~~^~~~~~~~~~
supertrees.cpp:106:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for(int j = 0; j < w.size(); j++){
      |                        ~~^~~~~~~~~~
supertrees.cpp:110:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |         for(int j = 1; j < dd.size(); j++){
      |                        ~~^~~~~~~~~~~
supertrees.cpp:119:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |         for(int i = 0; i < w.size(); i++){
      |                        ~~^~~~~~~~~~
supertrees.cpp:124:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |             for(int j = 1; j < adj[i].size(); j++){
      |                            ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1336 KB Output is correct
7 Correct 128 ms 22096 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1336 KB Output is correct
7 Correct 128 ms 22096 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1260 KB Output is correct
13 Correct 119 ms 22084 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 604 KB Output is correct
17 Correct 54 ms 8216 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5852 KB Output is correct
21 Correct 137 ms 24076 KB Output is correct
22 Correct 121 ms 24104 KB Output is correct
23 Correct 133 ms 23948 KB Output is correct
24 Correct 119 ms 23984 KB Output is correct
25 Correct 55 ms 10064 KB Output is correct
26 Correct 51 ms 10064 KB Output is correct
27 Correct 126 ms 24076 KB Output is correct
28 Correct 120 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 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1116 KB Output is correct
9 Correct 123 ms 22100 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1112 KB Output is correct
13 Correct 120 ms 22044 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 55 ms 8220 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Incorrect 31 ms 6424 KB Too many ways to get from 0 to 1, should be 0 found no less than 1
22 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 1 ms 344 KB Output is correct
4 Correct 32 ms 5796 KB Output is correct
5 Correct 129 ms 24144 KB Output is correct
6 Correct 125 ms 24148 KB Output is correct
7 Correct 128 ms 24148 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Incorrect 32 ms 6228 KB Too many ways to get from 0 to 1, should be 0 found no less than 1
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1336 KB Output is correct
7 Correct 128 ms 22096 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1260 KB Output is correct
13 Correct 119 ms 22084 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 604 KB Output is correct
17 Correct 54 ms 8216 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5852 KB Output is correct
21 Correct 137 ms 24076 KB Output is correct
22 Correct 121 ms 24104 KB Output is correct
23 Correct 133 ms 23948 KB Output is correct
24 Correct 119 ms 23984 KB Output is correct
25 Correct 55 ms 10064 KB Output is correct
26 Correct 51 ms 10064 KB Output is correct
27 Correct 126 ms 24076 KB Output is correct
28 Correct 120 ms 24148 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1116 KB Output is correct
37 Correct 123 ms 22100 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 5 ms 1112 KB Output is correct
41 Correct 120 ms 22044 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 55 ms 8220 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Incorrect 31 ms 6424 KB Too many ways to get from 0 to 1, should be 0 found no less than 1
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1336 KB Output is correct
7 Correct 128 ms 22096 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1260 KB Output is correct
13 Correct 119 ms 22084 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 604 KB Output is correct
17 Correct 54 ms 8216 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5852 KB Output is correct
21 Correct 137 ms 24076 KB Output is correct
22 Correct 121 ms 24104 KB Output is correct
23 Correct 133 ms 23948 KB Output is correct
24 Correct 119 ms 23984 KB Output is correct
25 Correct 55 ms 10064 KB Output is correct
26 Correct 51 ms 10064 KB Output is correct
27 Correct 126 ms 24076 KB Output is correct
28 Correct 120 ms 24148 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1116 KB Output is correct
37 Correct 123 ms 22100 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 5 ms 1112 KB Output is correct
41 Correct 120 ms 22044 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 55 ms 8220 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Incorrect 31 ms 6424 KB Too many ways to get from 0 to 1, should be 0 found no less than 1
50 Halted 0 ms 0 KB -