제출 #395221

#제출 시각아이디문제언어결과실행 시간메모리
395221irmuun자매 도시 (APIO20_swap)C++17
컴파일 에러
0 ms0 KiB
#include "swap.h" #include<bits/stdc++.h> using namespace std; int a,b,i,n,m,link[200000],edge[200000],sz[200000],x,y,ans[200000],h[200000],p[200000],d,e; pair<int, pair<int,int> >p[200000]; int find(int x){ if(link[x]==x){ return x; } return link[x]=find(link[x]); } bool same(int a,int b){ if(find(a)==find(b)){ return true; } else{ return false; } } void unite(int a,int b){ a=find(a); b=find(b); if(sz[a]<sz[b]){ swap(a,b); } if(ans[b]==1){ ans[a]=1; } link[b]=a; sz[a]+=sz[b]; } void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) { m=M; n=N; for(i=0;i<M;i++){ p[i].first=W[i]; p[i].second.first=U[i]; p[i].second.second=V[i]; h[U[i]]++; h[V[i]]++; } sort(p,p+m); for(i=0;i<n;i++){ p[h[i]]++; } } int getMinimumFuelCapacity(int X, int Y) { if(h[2]==n){ return p[m-1].first; } if(p[1]==n-1){ for(i=0;i<m;i++){ if(p[i].second.second==X){ d=p[i].first; } if(p[i].second.second==Y){ e=p[i].first; } } return max(p[2].first,max(d,e)); } for(i=0;i<n;i++){ link[i]=i; sz[i]=1; edge[i]=0; ans[i]=0; } for(i=0;i<m;i++){ x=p[i].second.first; y=p[i].second.second; edge[x]++; edge[y]++; if(find(x)==find(y)||edge[x]>2||edge[y]>2){ ans[find(x)]=1; ans[find(y)]=1; } unite(x,y); if(find(X)==find(Y)&&ans[find(X)]==1){ return p[i].first; } } return -1; }

컴파일 시 표준 에러 (stderr) 메시지

swap.cpp:5:26: error: conflicting declaration 'std::pair<int, std::pair<int, int> > p [200000]'
    5 | pair<int, pair<int,int> >p[200000];
      |                          ^
swap.cpp:4:78: note: previous declaration as 'int p [200000]'
    4 | int a,b,i,n,m,link[200000],edge[200000],sz[200000],x,y,ans[200000],h[200000],p[200000],d,e;
      |                                                                              ^
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:36:10: error: request for member 'first' in 'p[i]', which is of non-class type 'int'
   36 |     p[i].first=W[i];
      |          ^~~~~
swap.cpp:37:10: error: request for member 'second' in 'p[i]', which is of non-class type 'int'
   37 |     p[i].second.first=U[i];
      |          ^~~~~~
swap.cpp:38:10: error: request for member 'second' in 'p[i]', which is of non-class type 'int'
   38 |     p[i].second.second=V[i];
      |          ^~~~~~
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:49:19: error: request for member 'first' in 'p[(m - 1)]', which is of non-class type 'int'
   49 |     return p[m-1].first;
      |                   ^~~~~
swap.cpp:53:15: error: request for member 'second' in 'p[i]', which is of non-class type 'int'
   53 |       if(p[i].second.second==X){
      |               ^~~~~~
swap.cpp:54:16: error: request for member 'first' in 'p[i]', which is of non-class type 'int'
   54 |         d=p[i].first;
      |                ^~~~~
swap.cpp:56:15: error: request for member 'second' in 'p[i]', which is of non-class type 'int'
   56 |       if(p[i].second.second==Y){
      |               ^~~~~~
swap.cpp:57:16: error: request for member 'first' in 'p[i]', which is of non-class type 'int'
   57 |         e=p[i].first;
      |                ^~~~~
swap.cpp:60:21: error: request for member 'first' in 'p[2]', which is of non-class type 'int'
   60 |     return max(p[2].first,max(d,e));
      |                     ^~~~~
swap.cpp:69:12: error: request for member 'second' in 'p[i]', which is of non-class type 'int'
   69 |     x=p[i].second.first;
      |            ^~~~~~
swap.cpp:70:12: error: request for member 'second' in 'p[i]', which is of non-class type 'int'
   70 |     y=p[i].second.second;
      |            ^~~~~~
swap.cpp:79:19: error: request for member 'first' in 'p[i]', which is of non-class type 'int'
   79 |       return p[i].first;
      |                   ^~~~~