제출 #1056964

#제출 시각아이디문제언어결과실행 시간메모리
1056964Malix수천개의 섬 (IOI22_islands)C++17
컴파일 에러
0 ms0 KiB
#include "islands.h" #include <variant> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vii; typedef pair<int,int> pi; typedef vector<pi> pii; typedef tuple<int,int,int> tii; typedef vector<ll> li; typedef vector<li> lii; #define REP(i,a,b) for(int i=a;i<b;i++) #define F first #define S second #define PB push_back #define MP make_pair #define LSOne(s) ((s)&(-s)) ll INF=1e18+10; int inf=1e9+10; ll M=1e9+7; int n,m; vi ans; vector<pii> arr; vi vis; void bfs(int x){ vis[x]=1; int s=arr[x].size(); if(s==1){ ans.PB(-1); return; } if(s==2){ ans.PB(arr[x][0].S); bfs(a[x][0].F); if(ans.back()==-1)return; ans.PB(a[x][0].S); return; } int k=0; if(vis[arr[x][k].F])k++; int x=arr[x][k].S; int y=-1; for(auto u:arr[arr[x][k].F])if(u.F=x)y=u.S; k++; if(vis[arr[x][k].F])k++; int c=arr[x][1].S; int d=-1; for(auto u:arr[arr[x][k].F])if(u.F==x)d=u.S; ans.PB(x);ans.PB(y);ans.PB(c);ans.PB(d);ans.PB(y);ans.PB(x);ans.PB(d);ans.PB(c); return; } std::variant<bool, std::vector<int>> find_journey( int N, int M, std::vector<int> U, std::vector<int> V) { n=N;m=M; if(n==2){ if(m<=2)return false; vi a; REP(i,0,m)if(U[i]==0)a.PB(i); int p=-1; REP(i,0,m)if(U[i]!=0)p=i; int k=a.size(); if(k<2||p==-1)return false; ans.PB(a[0]);ans.PB(p);ans.PB(a[1]);ans.PB(a[0]);ans.PB(p);ans.PB(a[1]); return ans; } arr.resize(n); REP(i,0,m)arr[U[i]].PB({V[i],i}); if(arr[0].size()>=2){ int x=arr[0][0].S; int y=-1; for(auto u:arr[arr[0][0].F])if(u.F==0)y=u.S; int c=arr[0][1].S; int d=-1; for(auto u:arr[arr[0][1].F])if(u.F==0)d=u.S; ans.PB(x);ans.PB(y);ans.PB(c);ans.PB(d);ans.PB(y);ans.PB(x);ans.PB(d);ans.PB(c); return ans; } vis.resize(n,0); vis[0]=1; ans.PB(a[0][0].S); bfs(arr[0][0].F); if(ans.back()==-1)return false; ans.PB(a[0][0].S); return ans; }

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

islands.cpp: In function 'void bfs(int)':
islands.cpp:40:9: error: 'a' was not declared in this scope
   40 |     bfs(a[x][0].F);
      |         ^
islands.cpp:47:7: error: declaration of 'int x' shadows a parameter
   47 |   int x=arr[x][k].S;
      |       ^
islands.cpp:31:14: note: 'int x' previously declared here
   31 | void bfs(int x){
      |          ~~~~^
islands.cpp:49:37: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   49 |   for(auto u:arr[arr[x][k].F])if(u.F=x)y=u.S;
      |                                  ~~~^~
islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:87:10: error: 'a' was not declared in this scope
   87 |   ans.PB(a[0][0].S);
      |          ^