제출 #1235746

#제출 시각아이디문제언어결과실행 시간메모리
1235746MuhammadSaram수천개의 섬 (IOI22_islands)C++20
컴파일 에러
0 ms0 KiB
#include "islands.h"
#include <bits/stdc++.h>

using namespace std;

const int M = 1000;

vector<int> nei[M],ans;
map<pair<int,int>,int> ind; 
int vis[M], par[M];

void dfs(int u)
{
	vis[u]=1;
	if (ans.size()) return;
	for (int i:nei[u])
	{
		if (!vis[i])
			par[i]=u,dfs(i);
		else if(vis[i]==1)
		{
			int v=u;
			while (v)
				ans.push_back(ind[{par[v],v}]),v=par[v];
			reverse(ans.begin(),ans.end());
			ans.push_back(ind[{u,i}]);
			int v=u;
			vector<int> c;
			while (v!=i)
				c.push_back(ind[{par[v],v}]),v=par[v];
			reverse(c.begin(),c.end());
			c.push_back(ind[{u,i}]);
			for (int x:c)
				ans.push_back(x+1);
			reverse(c.begin(),c.end());
			for (int x:c)
				ans.push_back(x);
			for (int x:c)
				ans.push_back(x+1);
			int v=i;
			while (v)
				ans.push_back(ind[{par[v],v}]),v=par[v];
		}
		if (ans.size()) return;
	}
	vis[u]=2;
}

variant<bool, vector<int>> find_journey(int n, int m, vector<int> U, vector<int> V)
{
	for (int i=0;i<m;i+=2)
		nei[U[i]].push_back(V[i]),ind[{U[i],V[i]}]=i;
	dfs(0);
	if (ans.size()) return ans;
	return false;
}

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

islands.cpp: In function 'void dfs(int)':
islands.cpp:27:29: error: redeclaration of 'int v'
   27 |                         int v=u;
      |                             ^
islands.cpp:22:29: note: 'int v' previously declared here
   22 |                         int v=u;
      |                             ^
islands.cpp:40:29: error: redeclaration of 'int v'
   40 |                         int v=i;
      |                             ^
islands.cpp:22:29: note: 'int v' previously declared here
   22 |                         int v=u;
      |                             ^