답안 #475197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475197 2021-09-21T12:16:24 Z bigo Trampoline (info1cup20_trampoline) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define pii pair<int, int>
vector<vector<int>>vec;
vector<bool>visit;
void dfs(int v) {
	visit[v] = true;
	for (int i = 0; i < vec[v].size(); i++) {
		if (!visit[vec[v][i]])
			dfs(vec[v][i]);
	}
}
int main() {
	int r, c, n;
	cin >> r >> c >> n;
	set<pii>green;
	int a, b;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		a--, b--;
		green.insert({ a,b });
	}
	vec.resize(r * c);
	visit.resize(r * c, false);
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			if (green.find({ i,j }) != green.end()) {
				if(i!=r-1)
					vec[i * c + j].push_back(i * c + j + 1);
				if(j!=c-1)
					vec[i * c + j].push_back((i + 1) * c + j);
			}
			else {
				if(j!=c-1)
					vec[i * c + j].push_back(i * c + j + 1);
			}
		}
	}
	int t;
	cin >> t;
	while (t--) {
		int y1, x1, y2, x2;
		cin >> y1 >> x1 >> y2 >> x2;
		y1--, x1--, y2--, x2--;
		dfs(y1 * c + x1);
		if (visit[y2 * c + x2])
			cout << "YES";
		else
			cout << "NO";
		cout << endl;
		for (int i = 0; i < r * c; i++)
			visit[i] = false;
	}
}

Compilation message

trampoline.cpp: In function 'void dfs(int)':
trampoline.cpp:10:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for (int i = 0; i < vec[v].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~
trampoline.cpp: In function 'int main()':
trampoline.cpp:18:2: error: 'set' was not declared in this scope
   18 |  set<pii>green;
      |  ^~~
trampoline.cpp:4:1: note: 'std::set' is defined in header '<set>'; did you forget to '#include <set>'?
    3 | #include <cmath>
  +++ |+#include <set>
    4 | using namespace std;
trampoline.cpp:18:9: error: expected primary-expression before '>' token
   18 |  set<pii>green;
      |         ^
trampoline.cpp:18:10: error: 'green' was not declared in this scope
   18 |  set<pii>green;
      |          ^~~~~