답안 #116669

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116669 2019-06-13T13:51:44 Z IOrtroiii CEOI16_icc (CEOI16_icc) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;

const int N = 105;

int qa[N], qb[N];

int query(vector<int> a, vector<int> b) {
   int sza = a.size(), szb = b.size();
   for (int i = 0; i < sza; ++i) {
      qa[i] = a[i];
   }
   for (int i = 0; i < szb; ++i) {
      qb[i] = b[i];
   }
   return query(sza, szb, qa, qb);
}

int fnd(vector<int> from, vector<int> to) {
   int l = 0, r = from.size() - 1;
   while (l < r) {
      int md = (l + r) >> 1;
      if (query(vector<int>(from.begin(), from.begin() + md + 1), to)) {
         r = md;
      } else {
         l = md + 1;
      }
   }
   return from[l];
}

int p[N];
vector<int> comp[N];

int getp(int u) {
   if (p[u] == u) {
      return u;
   } else {
      return p[u] = getp(p[u]);
   }
}

void mrg(int u, int v) {
   u = getp(u), v = getp(v);
   if (comp[u].size() < comp[v].size()) {
      swap(u, v);
   }
   p[v] = u;
   for (int w : comp[v]) {
      comp[u].push_back(w);
   }
}

void modify(vector<int> l, vector<int> r) {
   int u = fnd(l, r);
   int v = fnd(r, l);
   mrg(u, v);
   setRoad(u, v);
}

void solve() {
   vector<int> roots;
   for (int i = 1; i <= n; ++i) {
      if (p[i] == i) {
         roots.push_back(i);
      }
   }
   for (int i = 0; (1 << i) < roots.size(); ++i) {
      vector<int> l, r;
      for (int j = 0; j < roots.size(); ++j) {
         if (j & (1 << i)) {
            for (int v : comp[roots[j]]) {
               l.push_back(v);
            }
         } else {
            for (int v : comp[root[j]) {
               r.push_back(v);
            }
         }
      }
      if (query(l, r)) {
         modify(l, r);
         return;
      }
   }
}

void run(int n) {
   for (int i = 1; i <= n; ++i) {
      p[i] = i;
      comp[i].push_back(i);
   }
   for (int i = 0; i < n - 1; ++i) {
      solve();
   }
}

Compilation message

icc.cpp: In function 'void solve()':
icc.cpp:64:25: error: 'n' was not declared in this scope
    for (int i = 1; i <= n; ++i) {
                         ^
icc.cpp:69:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; (1 << i) < roots.size(); ++i) {
                    ~~~~~~~~~^~~~~~~~~~~~~~
icc.cpp:71:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int j = 0; j < roots.size(); ++j) {
                       ~~^~~~~~~~~~~~~~
icc.cpp:77:31: error: 'root' was not declared in this scope
             for (int v : comp[root[j]) {
                               ^~~~
icc.cpp:77:31: note: suggested alternative: 'roots'
             for (int v : comp[root[j]) {
                               ^~~~
                               roots
icc.cpp:77:38: error: expected ']' before ')' token
             for (int v : comp[root[j]) {
                                      ^