이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std ;
const int N = 1002;
int dsu[N] , sz[N];
int get(int u){
if(u == dsu[u])
return u ;
return dsu[u] = get(dsu[u]);
}
void connect(int u , int v){
u = get(u) , v = get(v);
if(u == v)return ;
if(sz[u] > sz[v])swap(u , v);
sz[v] += sz[u];
dsu[u] = v ;
}
bool same(int u , int v){
u = get(u) , v = get(v);
return u == v ;
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> answer (n , vector<int> (n , 0));
for(int i = 0 ; i < n ; i ++)sz[i] = 1 , dsu[i] = i ;
int mx[n] = {} , cnt[n] = {} , cnt1[n] = {};
for(int i = 0 ; i < n ; i ++){
for(int j = 0 ; j < n ; j ++){
if(p[i][j])connect(i , j);
if(i == j)continue;
mx[i] = max(mx[i] , p[i][j]);
mx[j] = max(mx[j] , p[i][j]);
cnt[i] += (p[i][j] == 2 );cnt1[i] += (p[i][j] == 1);
}
}
map<int, set<int> > mp ;
for(int i = 0 ; i < n ; i ++){
for(int j = 0 ; j < n ;j ++)
{
// if(p[i][j] == 0&& same(i , j) || (p[i][j] && sz[get(dsu[i])] == 2))return 0 ;
if(p[i][j] && i != j)mp[dsu[i]].insert(i) , mp[dsu[i]].insert(j);
}
}
for(auto f : mp){
int node = - 1 ;
vector<int> v , el ;
for(auto ff : f.second){
if(cnt[ff] == f.second.size() - 1 )v.push_back(ff);
else el.push_back(ff);
//if(cnt[ff] && cnt1[ff])v.push_back()
}
for(auto ff : el){
if(cnt1[ff] == f.second.size() - 1 - v.size()){
node = ff ;
v.push_back(ff);
break;
}
}
int past = v[0];
for(int i = 1 ; i < v.size() ; i ++){
answer[past][v[i]] = answer[v[i]][past] = 1 ;
past = v[i];
}
answer[v[0]][v[v.size() - 1]] = answer[v[v.size() - 1]][v[0]] = 1 ;
v.clear();
if(~node){
for(auto ff : el){
if(ff != node)v.push_back(ff);
}
past = v[0];
for(int i = 1 ; i < v.size() ; i ++){
answer[past][v[i]] = answer[v[i]][past] = 1 ;
past = v[i];
}
answer[past][node] = answer[node][past] = 1 ;
}
}
build(answer);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:74:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | if(cnt[ff] == f.second.size() - 1 )v.push_back(ff);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:79:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | if(cnt1[ff] == f.second.size() - 1 - v.size()){
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:88:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int i = 1 ; i < v.size() ; i ++){
| ~~^~~~~~~~~~
supertrees.cpp:104:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for(int i = 1 ; i < v.size() ; i ++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |