Submission #394881

# Submission time Handle Problem Language Result Execution time Memory
394881 2021-04-27T12:00:29 Z Sugardorj Swapping Cities (APIO20_swap) C++14
Compilation error
0 ms 0 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
long long  i,j,s,t;
long long link[261523],size[234567],c[234567],a[234567],l=12345678,r,tt,k,y,z,n,m,x;
pair<long long,long long>p[234567];

void init(int N, int M, vector <int> U, vector <int> V, vector <int> W) {
    n = N;
    m = M;
    for (i = 0; i <m; i ++){
        p[i].first=W[i];
        p[i].second=U[i]*l+V[i];
    }
    sort (p,p+m);
}
long long find(long long x) {
    while (x != link[x]) 
        x = link[x];
    return x;
}
bool same(long long x, long long y) {
    return find(x) == find(y);
}
void unite(long long x, long long y) {
    x = find(x);
    y = find(y);
    if (size[x] < size[y]) 
        swap(x,y);
    size[x] += size[y];
    if (c[x]+c[y]>0)
        c[x]=1;
    link[y] = x;
}
int getMinimumFuelCapacity(int u, int v) {
    for (i = 1; i<=n; i ++){
        link[i]=i;
        size[i]=1;
        c[i]=0;
        a[i]=0;
    }
    for (i = 0; i <m; i ++){
        x=p[i].second/l;
        y=p[i].second%l;
        a[x]++;
        a[y]++;
        if (find[x]==find[y]||a[x]>2||a[y]>2){
            c[find[x]]=1;
        }
        unite(x,y);
        
        
        if (find[u]==find[v]&&c[find[u]]==1){
            return w[i];
        }
    }
    
    
    return -1;
}

Compilation message

swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:47:19: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   47 |         if (find[x]==find[y]||a[x]>2||a[y]>2){
      |                   ^
swap.cpp:47:28: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   47 |         if (find[x]==find[y]||a[x]>2||a[y]>2){
      |                            ^
swap.cpp:48:21: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   48 |             c[find[x]]=1;
      |                     ^
swap.cpp:53:19: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   53 |         if (find[u]==find[v]&&c[find[u]]==1){
      |                   ^
swap.cpp:53:28: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   53 |         if (find[u]==find[v]&&c[find[u]]==1){
      |                            ^
swap.cpp:53:39: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   53 |         if (find[u]==find[v]&&c[find[u]]==1){
      |                                       ^
swap.cpp:54:20: error: 'w' was not declared in this scope
   54 |             return w[i];
      |                    ^