Submission #85982

# Submission time Handle Problem Language Result Execution time Memory
85982 2018-11-23T16:22:14 Z tjdgus4384 None (KOI17_civilization) C++14
Compilation error
0 ms 0 KB
#include<cstdio>
#include<string.h>
#include<queue>
using namespace std;
queue<pair<pair<int, int>, pair<int, int> > > q;
int pa[100001], sz[100001], rank[100001], ar[2001][2001];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int find(int u)
{
    if(pa[u] == u) return u;
    return pa[u] = find(pa[u]);
}

void merge(int u, int v)
{
    u = find(u); v = find(v);
    if(u == v) return;
    if(rank[u] > rank[v]) swap(u, v);
    pa[u] = v;
    sz[v] += sz[u];
    if(rank[u] == rank[v]) rank[v]++;
}

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 1;i <= k;i++)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        q.push({{x, y}, {i, 0}});
        pa[i] = i;
        sz[i] = 1;
    }
    while(!q.empty())
    {
        int x = q.front().first.first;
        int y = q.front().first.second;
        int s = q.front().second.first;
        int t = q.front().second.second;
        q.pop();
        if(ar[x][y] == 0)
        {
            ar[x][y] = s;
            for(int i = 0;i < 4;i++)
            {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if(nx < 1 || nx > n || ny < 1 || ny > n) continue;
                if(ar[nx][ny] == 0) q.push({{nx, ny}, {s, t + 1}});
                else merge(ar[nx][ny], s);
            }
        }
        else
        {
            merge(ar[x][y], s);
        }
        if(sz[find(1)] == k)
        {
            printf("%d", t);
            return 0;
        }
    }
}

Compilation message

civilization.cpp: In function 'void merge(int, int)':
civilization.cpp:20:8: error: reference to 'rank' is ambiguous
     if(rank[u] > rank[v]) swap(u, v);
        ^~~~
civilization.cpp:6:29: note: candidates are: int rank [100001]
 int pa[100001], sz[100001], rank[100001], ar[2001][2001];
                             ^~~~
In file included from /usr/include/c++/7/bits/move.h:54:0,
                 from /usr/include/c++/7/bits/stl_pair.h:59,
                 from /usr/include/c++/7/bits/stl_algobase.h:64,
                 from /usr/include/c++/7/deque:60,
                 from /usr/include/c++/7/queue:60,
                 from civilization.cpp:3:
/usr/include/c++/7/type_traits:1468:12: note:                 template<class> struct std::rank
     struct rank
            ^~~~
civilization.cpp:20:18: error: reference to 'rank' is ambiguous
     if(rank[u] > rank[v]) swap(u, v);
                  ^~~~
civilization.cpp:6:29: note: candidates are: int rank [100001]
 int pa[100001], sz[100001], rank[100001], ar[2001][2001];
                             ^~~~
In file included from /usr/include/c++/7/bits/move.h:54:0,
                 from /usr/include/c++/7/bits/stl_pair.h:59,
                 from /usr/include/c++/7/bits/stl_algobase.h:64,
                 from /usr/include/c++/7/deque:60,
                 from /usr/include/c++/7/queue:60,
                 from civilization.cpp:3:
/usr/include/c++/7/type_traits:1468:12: note:                 template<class> struct std::rank
     struct rank
            ^~~~
civilization.cpp:23:8: error: reference to 'rank' is ambiguous
     if(rank[u] == rank[v]) rank[v]++;
        ^~~~
civilization.cpp:6:29: note: candidates are: int rank [100001]
 int pa[100001], sz[100001], rank[100001], ar[2001][2001];
                             ^~~~
In file included from /usr/include/c++/7/bits/move.h:54:0,
                 from /usr/include/c++/7/bits/stl_pair.h:59,
                 from /usr/include/c++/7/bits/stl_algobase.h:64,
                 from /usr/include/c++/7/deque:60,
                 from /usr/include/c++/7/queue:60,
                 from civilization.cpp:3:
/usr/include/c++/7/type_traits:1468:12: note:                 template<class> struct std::rank
     struct rank
            ^~~~
civilization.cpp:23:19: error: reference to 'rank' is ambiguous
     if(rank[u] == rank[v]) rank[v]++;
                   ^~~~
civilization.cpp:6:29: note: candidates are: int rank [100001]
 int pa[100001], sz[100001], rank[100001], ar[2001][2001];
                             ^~~~
In file included from /usr/include/c++/7/bits/move.h:54:0,
                 from /usr/include/c++/7/bits/stl_pair.h:59,
                 from /usr/include/c++/7/bits/stl_algobase.h:64,
                 from /usr/include/c++/7/deque:60,
                 from /usr/include/c++/7/queue:60,
                 from civilization.cpp:3:
/usr/include/c++/7/type_traits:1468:12: note:                 template<class> struct std::rank
     struct rank
            ^~~~
civilization.cpp:23:28: error: reference to 'rank' is ambiguous
     if(rank[u] == rank[v]) rank[v]++;
                            ^~~~
civilization.cpp:6:29: note: candidates are: int rank [100001]
 int pa[100001], sz[100001], rank[100001], ar[2001][2001];
                             ^~~~
In file included from /usr/include/c++/7/bits/move.h:54:0,
                 from /usr/include/c++/7/bits/stl_pair.h:59,
                 from /usr/include/c++/7/bits/stl_algobase.h:64,
                 from /usr/include/c++/7/deque:60,
                 from /usr/include/c++/7/queue:60,
                 from civilization.cpp:3:
/usr/include/c++/7/type_traits:1468:12: note:                 template<class> struct std::rank
     struct rank
            ^~~~
civilization.cpp: In function 'int main()':
civilization.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~
civilization.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~