Submission #584371

#TimeUsernameProblemLanguageResultExecution timeMemory
584371TimDee슈퍼트리 잇기 (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i=0; i<n; ++i)
#define all(a) a.begin(), a.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define pi pair<int,int>
#define f first
#define s second

int mirror(vector<vector<int>>&a) {
  int n=a.size();
  for (int i=0; i<n; ++i) {
    for (int j=i+1; j<n; ++j) {
      if (a[i][j]!=a[j][i]) return 0;
    }
  }
  forn(i,n) if (a[i][i]!=1) return 0;
  return 1;
}

int bfs(vector<vector<int>>&p, vector<int>&vis, int v, vector<pair<int,int>>&edges) {

  vector<int> one, two;
  vector<int> cycle;

  forn(i,n) {
    if (i==v) continue;
    if (p[v][i]==1) one.pb(i);
    else if (p[v][i]==2) two.pb(i);
  }

  forn(i,one.size()) {
    forn(j,one.size()) {
      if (i==j) continue;
      if (p[one[i]][one[j]]!=1) return 0;
    }
  }
  forn(i,one.size()) edges.pb(mp(v,one[i]));

  forn(i,one.size()) vis[one[i]]=1;
  forn(i,two.size()) vis[two[i]]=1;
  vis[v]=1;
 
  if (!two.size()) {
    return 1;
  } else if (two.size()==1) return 0;
  else {
    forn(i,one.size()) {
      forn(j,two.size()) {
        if (p[one[i]][two[j]]!=2) return 0;
      }
    }
    cycle={v};
    forn(i,two.size()) {
      int foo=1;
      forn(j,cycle.size()) {
        if (p[two[i]][cycle[j]]==2) continue;
        else {foo=0; break;}
      }
      if (foo) cycle.pb(two[i]);
    }
  }

  queue<int> q;
  forn(i,cycle.size()) {
    if (cycle[i]!=v) q.push(cycle[i]);
  }

  while (!q.empty()) {
 
    int v=q.front(); q.pop();
    
    vector<int> one, two;

    forn(i,n) {
      if (i==v) continue;
      if (p[v][i]==1) one.pb(i);
      else if (p[v][i]==2) two.pb(i);
    }

    forn(i,one.size()) {
      forn(j,one.size()) {
        if (i==j) continue;
        if (p[one[i]][one[j]]!=1) return 0;
      }
    }
    forn(i,one.size()) edges.pb(mp(v,one[i]));

    forn(i,one.size()) vis[one[i]]=1;
    forn(i,two.size()) vis[two[i]]=1;
    vis[v]=1;
 
    if (!two.size()) {
      continue;
    } else if (two.size()==1) return 0;
    else {
      forn(i,one.size()) {
        forn(j,two.size()) {
          if (p[one[i]][two[j]]!=2) return 0;
        }
      }
    }
  
  }

  forn(i,cycle.size()) {
    edges.pb(mp(cycle[i],cycle[(i+1)%cycle.size()]));
  }

  return 1;

}

int construct(std::vector<std::vector<int>> p) {
  int n = p.size();
  
  vector<vector<int>> a(n); 
  forn(i,n) a[i].assign(n,0);
 
  if (!mirror(p)) return 0;
 
  queue<int> q;
  q.push(0);
 
  vector<pair<int,int>> edges;
  vector<int> vis(n,0);
 
  forn(i,n) {
    if (vis[i]) continue;
    int x=bfs(p,vis,i,edges);
    if (x==0) return 0;
  }
 
  for (auto E:edges) {
    int u=E.f, v=E.s;
    a[u][v]=1;
    a[v][u]=1;
  }
 
  build(a);
  return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int bfs(std::vector<std::vector<int> >&, std::vector<int>&, int, std::vector<std::pair<int, int> >&)':
supertrees.cpp:28:10: error: 'n' was not declared in this scope
   28 |   forn(i,n) {
      |          ^
supertrees.cpp:4:35: note: in definition of macro 'forn'
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
      |                                   ^
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   34 |   forn(i,one.size()) {
      |        ~~~~~~~~~~~~               
supertrees.cpp:34:3: note: in expansion of macro 'forn'
   34 |   forn(i,one.size()) {
      |   ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   35 |     forn(j,one.size()) {
      |          ~~~~~~~~~~~~             
supertrees.cpp:35:5: note: in expansion of macro 'forn'
   35 |     forn(j,one.size()) {
      |     ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   40 |   forn(i,one.size()) edges.pb(mp(v,one[i]));
      |        ~~~~~~~~~~~~               
supertrees.cpp:40:3: note: in expansion of macro 'forn'
   40 |   forn(i,one.size()) edges.pb(mp(v,one[i]));
      |   ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   42 |   forn(i,one.size()) vis[one[i]]=1;
      |        ~~~~~~~~~~~~               
supertrees.cpp:42:3: note: in expansion of macro 'forn'
   42 |   forn(i,one.size()) vis[one[i]]=1;
      |   ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   43 |   forn(i,two.size()) vis[two[i]]=1;
      |        ~~~~~~~~~~~~               
supertrees.cpp:43:3: note: in expansion of macro 'forn'
   43 |   forn(i,two.size()) vis[two[i]]=1;
      |   ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   50 |     forn(i,one.size()) {
      |          ~~~~~~~~~~~~             
supertrees.cpp:50:5: note: in expansion of macro 'forn'
   50 |     forn(i,one.size()) {
      |     ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   51 |       forn(j,two.size()) {
      |            ~~~~~~~~~~~~           
supertrees.cpp:51:7: note: in expansion of macro 'forn'
   51 |       forn(j,two.size()) {
      |       ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   56 |     forn(i,two.size()) {
      |          ~~~~~~~~~~~~             
supertrees.cpp:56:5: note: in expansion of macro 'forn'
   56 |     forn(i,two.size()) {
      |     ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   58 |       forn(j,cycle.size()) {
      |            ~~~~~~~~~~~~~~         
supertrees.cpp:58:7: note: in expansion of macro 'forn'
   58 |       forn(j,cycle.size()) {
      |       ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   67 |   forn(i,cycle.size()) {
      |        ~~~~~~~~~~~~~~             
supertrees.cpp:67:3: note: in expansion of macro 'forn'
   67 |   forn(i,cycle.size()) {
      |   ^~~~
supertrees.cpp:77:12: error: 'n' was not declared in this scope
   77 |     forn(i,n) {
      |            ^
supertrees.cpp:4:35: note: in definition of macro 'forn'
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
      |                                   ^
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   83 |     forn(i,one.size()) {
      |          ~~~~~~~~~~~~             
supertrees.cpp:83:5: note: in expansion of macro 'forn'
   83 |     forn(i,one.size()) {
      |     ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   84 |       forn(j,one.size()) {
      |            ~~~~~~~~~~~~           
supertrees.cpp:84:7: note: in expansion of macro 'forn'
   84 |       forn(j,one.size()) {
      |       ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   89 |     forn(i,one.size()) edges.pb(mp(v,one[i]));
      |          ~~~~~~~~~~~~             
supertrees.cpp:89:5: note: in expansion of macro 'forn'
   89 |     forn(i,one.size()) edges.pb(mp(v,one[i]));
      |     ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   91 |     forn(i,one.size()) vis[one[i]]=1;
      |          ~~~~~~~~~~~~             
supertrees.cpp:91:5: note: in expansion of macro 'forn'
   91 |     forn(i,one.size()) vis[one[i]]=1;
      |     ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   92 |     forn(i,two.size()) vis[two[i]]=1;
      |          ~~~~~~~~~~~~             
supertrees.cpp:92:5: note: in expansion of macro 'forn'
   92 |     forn(i,two.size()) vis[two[i]]=1;
      |     ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
   99 |       forn(i,one.size()) {
      |            ~~~~~~~~~~~~           
supertrees.cpp:99:7: note: in expansion of macro 'forn'
   99 |       forn(i,one.size()) {
      |       ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
  100 |         forn(j,two.size()) {
      |              ~~~~~~~~~~~~         
supertrees.cpp:100:9: note: in expansion of macro 'forn'
  100 |         forn(j,two.size()) {
      |         ^~~~
supertrees.cpp:4:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for (int i=0; i<n; ++i)
......
  108 |   forn(i,cycle.size()) {
      |        ~~~~~~~~~~~~~~             
supertrees.cpp:108:3: note: in expansion of macro 'forn'
  108 |   forn(i,cycle.size()) {
      |   ^~~~