답안 #629494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629494 2022-08-14T14:42:34 Z JJAnawat 슈퍼트리 잇기 (IOI20_supertrees) C++17
46 / 100
232 ms 23984 KB
#include "supertrees.h"
#include <vector>

using namespace std;

int par[1005];

int fi(int i){
    if(par[i]==i)
        return i;
    else
        return par[i]=fi(par[i]);
}

void un(int i,int j){
    par[fi(j)]=fi(i);
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> ans;
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		ans.push_back(row);
	}

	for(int i=0;i<n;i++)
        par[i]=i;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(p[i][j]==1&&fi(i)!=fi(j)){
                ans[i][j]=ans[j][i]=1;
                un(i,j);
            }
            if(p[i][j]==3||(p[i][j]==0&&fi(i)==fi(j)))
                return 0;
        }
    }

    for(int i=0;i<n;i++){
        vector<int> v;
        v.push_back(par[i]);

        for(int j=i+1;j<n;j++){
            if(p[i][j]==2&&fi(i)!=fi(j)){
                v.push_back(par[j]);
                un(i,j);
            }
        }

        if(v.size()==2)
            return 0;

        for(int k=0;k+1<v.size();k++)
            ans[v[k]][v[k+1]]=ans[v[k+1]][v[k]]=1;
        ans[v[0]][v[v.size()-1]]=ans[v[v.size()-1]][v[0]]=1;

    }

    for(int i=0;i<n;i++)
        ans[i][i]=0;

	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:56:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(int k=0;k+1<v.size();k++)
      |                     ~~~^~~~~~~~~
supertrees.cpp:62:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   62 |     for(int i=0;i<n;i++)
      |     ^~~
supertrees.cpp:65:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   65 |  build(ans);
      |  ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 174 ms 23984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 174 ms 23984 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1172 KB Output is correct
13 Correct 175 ms 23944 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 788 KB Output is correct
17 Correct 78 ms 14068 KB Output is correct
18 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 288 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 8 ms 1196 KB Output is correct
9 Correct 158 ms 23984 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 182 ms 23924 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 0 ms 292 KB Answer gives possible 1 while actual possible 0
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 47 ms 6220 KB Output is correct
5 Correct 181 ms 23912 KB Output is correct
6 Correct 165 ms 23924 KB Output is correct
7 Correct 232 ms 23924 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 45 ms 6248 KB Output is correct
10 Correct 171 ms 23928 KB Output is correct
11 Correct 173 ms 23884 KB Output is correct
12 Correct 185 ms 23888 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 292 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 41 ms 6256 KB Output is correct
17 Correct 164 ms 23924 KB Output is correct
18 Correct 176 ms 23948 KB Output is correct
19 Correct 199 ms 23912 KB Output is correct
20 Correct 161 ms 23892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 174 ms 23984 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1172 KB Output is correct
13 Correct 175 ms 23944 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 788 KB Output is correct
17 Correct 78 ms 14068 KB Output is correct
18 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 174 ms 23984 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1172 KB Output is correct
13 Correct 175 ms 23944 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 788 KB Output is correct
17 Correct 78 ms 14068 KB Output is correct
18 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
19 Halted 0 ms 0 KB -