Submission #731567

# Submission time Handle Problem Language Result Execution time Memory
731567 2023-04-27T14:44:27 Z abcvuitunggio ICC (CEOI16_icc) C++17
Compilation error
0 ms 0 KB
//#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
int g[101][101],n,u[101],v[101],id=1,cnt;
int query(int sa, int sb, int a[], int b[]){
    cnt++;
    for (int i=0;i<sa;i++)
        for (int j=0;j<sb;j++){
            if (a[i]<1||a[i]>n||b[j]<1||b[j]>n){
                cout << "Cities in query out of range.";
                exit(1);
            }
            if (g[a[i]][b[j]])
                return 1;
        }
    return 0;
}
void SetRoad(int a, int b){
    if (a<1||a>n||b<1||b>n){
        cout << "Road cannot exist.";
        exit(2);
    }
    if (!g[a][b]){
        cout << "Road " << a << ' ' << b << " doesn't exist.";
        exit(3);
    }
    id++;
    g[u[id]][v[id]]=g[v[id]][u[id]]=1;
}
#endif // LOCAL
int p[101];
vector <int> ve[101],root;
int f(int i){
    return (p[i]==i?i:p[i]=f(p[i]));
}
void unite(int i, int j){
    i=f(i);
    j=f(j);
    if (i>j)
        swap(i,j);
    p[j]=i;
    for (int k:ve[j])
        ve[i].push_back(k);
    ve[j].clear();
}
int ask(int x, int y, int a[], int b[]){
    int A[x],B[y];
    for (int i=0;i<x;i++)
        A[i]=a[i];
    for (int j=0;j<y;j++)
        B[j]=b[j];
    return query(x,y,A,B);
}
void findroad(){
    root.clear();
    for (int i=1;i<=n;i++)
        if (f(i)==i)
            root.push_back(i);
    for (int i=0;(1<<i)<root.size();i++){
        int sa=0,sb=0;
        for (int j=0;j<root.size();j++)
            if ((j>>i)&1)
                sb+=ve[root[j]].size();
            else
                sa+=ve[root[j]].size();
        int a[sa],b[sb],x=0,y=0;
        for (int j=0;j<root.size();j++){
            if ((j>>i)&1)
                for (int u:ve[root[j]]){
                    b[y]=u;
                    y++;
                }
            else
                for (int u:ve[root[j]]){
                    a[x]=u;
                    x++;
                }
        }
        if (query(sa,sb,a,b)){
            int l=1,r=sa,kq=-1,kq2=-1;
            while (l<=r){
                int mid=(l+r)>>1;
                if (ask(mid,sb,a,b)){
                    kq=mid;
                    r=mid-1;
                }
                else
                    l=mid+1;
            }
            l=1,r=sb;
            while (l<=r){
                int mid=(l+r)>>1;
                if (ask(sa,mid,a,b)){
                    kq2=mid;
                    r=mid-1;
                }
                else
                    l=mid+1;
            }
            SetRoad(a[kq-1],b[kq2-1]);
            unite(a[kq-1],b[kq2-1]);
            break;
        }
    }
}
void Run(int n){
    for (int i=1;i<=n;i++){
        p[i]=i;
        ve[i].push_back(i);
    }
    for (int i=1;i<n;i++)
        findroad();
}
#ifdef LOCAL
int main(){
    cin >> n;
    for (int i=1;i<n;i++)
        cin >> u[i] >> v[i];
    g[u[1]][v[1]]=g[v[1]][u[1]]=1;
    Run(n);
    cout << "You successfully found all the roads. Congratulations!\n";
    cout << "You've asked " << cnt << " queries.";
}
#endif // LOCAL

Compilation message

icc.cpp: In function 'int ask(int, int, int*, int*)':
icc.cpp:53:12: error: 'query' was not declared in this scope
   53 |     return query(x,y,A,B);
      |            ^~~~~
icc.cpp: In function 'void findroad()':
icc.cpp:57:21: error: 'n' was not declared in this scope
   57 |     for (int i=1;i<=n;i++)
      |                     ^
icc.cpp:60:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i=0;(1<<i)<root.size();i++){
      |                  ~~~~~~^~~~~~~~~~~~
icc.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for (int j=0;j<root.size();j++)
      |                      ~^~~~~~~~~~~~
icc.cpp:68:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for (int j=0;j<root.size();j++){
      |                      ~^~~~~~~~~~~~
icc.cpp:80:13: error: 'query' was not declared in this scope
   80 |         if (query(sa,sb,a,b)){
      |             ^~~~~
icc.cpp:101:13: error: 'SetRoad' was not declared in this scope
  101 |             SetRoad(a[kq-1],b[kq2-1]);
      |             ^~~~~~~