제출 #318342

#제출 시각아이디문제언어결과실행 시간메모리
318342NintsiChkhaidze슈퍼트리 잇기 (IOI20_supertrees)C++14
11 / 100
254 ms24168 KiB
#include "supertrees.h"
#include <iostream>
#include <vector>
#define pb push_back
using namespace std;
vector<vector<int>> answer;
vector <int> row,vec[1005],k;
bool f[1005];
int construct(vector<vector<int>> p) {
    int n = p.size();
    for(int i=0;i<n;i++){
        row.clear();
        for (int j=0;j<n;j++){
            if (p[i][j] == 3) return 0;
            if (p[i][i] != 1) return 0;
            row.pb(0);
        }
        answer.pb(row);
    }
    for (int i=0;i<n;i++){
        if (f[i]) continue;
        for (int j=0;j<n;j++){
            if (p[i][j] == 1 && i!=j){
                vec[i].pb(j);
                f[j]=1;
                answer[i][j]=answer[j][i]=1;
            }
        }
    }
    for(int i=0;i<n;i++) f[i]=0;
    for (int i=0;i<n;i++)
        for (int j=0;j<vec[i].size();j++)
           if (p[i][vec[i][j]] != 1) return 0;
    
    for(int i=0;i<n;i++){
        if(f[i]) continue;
        row.clear();
        for (int j=0;j<n;j++)
            if (p[i][j] == 2) f[j] = 1,row.pb(j);
        int st = i,cur = i;
        k.clear();
        k.pb(i);
        for (int j=0;j<row.size();j++){
            k.pb(row[j]);
            answer[row[j]][cur] = answer[cur][row[j]] = 1;
            cur = row[j];
        }
        if (row.size()==0) continue;
        if (row.size() == 1) {return 0;}
        for (int j=0;j<k.size();j++){
            for (int u = j+1;u<k.size();u++)
            if (p[k[j]][k[u]] != 2) {return 0;}
        }
        int last = row[row.size() - 1];
        answer[st][last] = answer[last][st] = 1;
        
    }
    
    build(answer);
    return 1;
}

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for (int j=0;j<vec[i].size();j++)
      |                      ~^~~~~~~~~~~~~~
supertrees.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for (int j=0;j<row.size();j++){
      |                      ~^~~~~~~~~~~
supertrees.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (int j=0;j<k.size();j++){
      |                      ~^~~~~~~~~
supertrees.cpp:51:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             for (int u = j+1;u<k.size();u++)
      |                              ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...