답안 #938925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938925 2024-03-05T21:17:06 Z Macker Simurgh (IOI17_simurgh) C++17
컴파일 오류
0 ms 0 KB
#include "simurgh.h"
#include <bits/stdc++.h>

typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define FOR(i, n) for (int i = 0; i < n; i++)

using namespace std;

set<pii> cur;
map<pii, int> fin;
map<pii, int> label;
vector<vector<int>> adj;
vector<int> vis;

vector<int> tovec(set<pii> a){
	vector<int> res;
	for (auto &i : a) {
		res.push_back(label[i]);
	}
	return res;
}

pii sdfs(int a, int p){
	vis[a] = 2;
	pii res = {1, 0};
	for (auto &b : adj[a]) {
		if(vis[b] != 2) {
			pii ret = sdfs(b, a);
			res.fi += ret.fi;
			res.se += ret.se;
		}
	}
	if(a == 0) return res;

	int base = count_common_roads(tovec(cur));
	cur.erase({p, a});
	set<int> samepar;
	bool parroyal = (res.se < res.fi);
	for (auto &b : adj[a]) {
		if(cur.find({a, b}) == cur.end() && cur.find({b, a}) == cur.end()){
			cur.insert({a, b});
			int cnt = count_common_roads(tovec(cur));
			cur.erase({a, b});
			if(cnt == base) samepar.insert(b);
			if(cnt < base) parroyal = 1;
			if(cnt > base) parroyal = 0;
		}
	}
	for (auto &b : adj[a]) {
		if(cur.find({a, b}) == cur.end() && cur.find({b, a}) == cur.end()){
			if(samepar.find(b) != samepar.end()){
				if(parroyal) {
					cur.insert({a, b});
					fin[{a, b}] = 1;
					res.se++;
				}
			}
			else {
				if(!parroyal) {
					cur.insert({a, b});
					fin[{a, b}] = 1;
					res.se++;
				}
			}
		}
	}
	return res;
}

void dfs(int a){
	vis[a] = 1;
	for (auto &b : adj[a]) {
		if(!vis[b]) {
			cur.insert({a, b});
			dfs(b);
		}
	}
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	adj.resize(n);
	vis.resize(n);
	FOR(i, u.size()){
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
		label[{u[i], v[i]}] = i;
		label[{v[i], u[i]}] = i;
	}
	dfs(0);
	sdfs(0, 0);

	vector<int> res;
	for (auto &i : fin) {
		if(i.se == 1) res.push_back(label[i.fi]);
	}
	return res;
}

Compilation message

simurgh.cpp:5:9: error: 'pair' does not name a type
    5 | typedef pair<int, int> pii;
      |         ^~~~
simurgh.cpp:13:5: error: 'pii' was not declared in this scope
   13 | set<pii> cur;
      |     ^~~
simurgh.cpp:13:8: error: template argument 1 is invalid
   13 | set<pii> cur;
      |        ^
simurgh.cpp:13:8: error: template argument 2 is invalid
simurgh.cpp:13:8: error: template argument 3 is invalid
simurgh.cpp:14:5: error: 'pii' was not declared in this scope
   14 | map<pii, int> fin;
      |     ^~~
simurgh.cpp:14:13: error: template argument 1 is invalid
   14 | map<pii, int> fin;
      |             ^
simurgh.cpp:14:13: error: template argument 3 is invalid
simurgh.cpp:14:13: error: template argument 4 is invalid
simurgh.cpp:15:5: error: 'pii' was not declared in this scope
   15 | map<pii, int> label;
      |     ^~~
simurgh.cpp:15:13: error: template argument 1 is invalid
   15 | map<pii, int> label;
      |             ^
simurgh.cpp:15:13: error: template argument 3 is invalid
simurgh.cpp:15:13: error: template argument 4 is invalid
simurgh.cpp:19:23: error: 'pii' was not declared in this scope
   19 | vector<int> tovec(set<pii> a){
      |                       ^~~
simurgh.cpp:19:26: error: template argument 1 is invalid
   19 | vector<int> tovec(set<pii> a){
      |                          ^
simurgh.cpp:19:26: error: template argument 2 is invalid
simurgh.cpp:19:26: error: template argument 3 is invalid
simurgh.cpp: In function 'std::vector<int> tovec(int)':
simurgh.cpp:21:17: error: 'begin' was not declared in this scope
   21 |  for (auto &i : a) {
      |                 ^
simurgh.cpp:21:17: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from simurgh.cpp:2:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from simurgh.cpp:2:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
simurgh.cpp:21:17: error: 'end' was not declared in this scope
   21 |  for (auto &i : a) {
      |                 ^
simurgh.cpp:21:17: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from simurgh.cpp:2:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from simurgh.cpp:2:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~
simurgh.cpp: At global scope:
simurgh.cpp:27:1: error: 'pii' does not name a type
   27 | pii sdfs(int a, int p){
      | ^~~
simurgh.cpp: In function 'void dfs(int)':
simurgh.cpp:78:8: error: request for member 'insert' in 'cur', which is of non-class type 'int'
   78 |    cur.insert({a, b});
      |        ^~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:9:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define FOR(i, n) for (int i = 0; i < n; i++)
......
   87 |  FOR(i, u.size()){
      |      ~~~~~~~~~~~                     
simurgh.cpp:87:2: note: in expansion of macro 'FOR'
   87 |  FOR(i, u.size()){
      |  ^~~
simurgh.cpp:90:8: error: invalid types 'int[<brace-enclosed initializer list>]' for array subscript
   90 |   label[{u[i], v[i]}] = i;
      |        ^
simurgh.cpp:91:8: error: invalid types 'int[<brace-enclosed initializer list>]' for array subscript
   91 |   label[{v[i], u[i]}] = i;
      |        ^
simurgh.cpp:94:2: error: 'sdfs' was not declared in this scope; did you mean 'dfs'?
   94 |  sdfs(0, 0);
      |  ^~~~
      |  dfs
simurgh.cpp:97:17: error: 'begin' was not declared in this scope
   97 |  for (auto &i : fin) {
      |                 ^~~
simurgh.cpp:97:17: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from simurgh.cpp:2:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from simurgh.cpp:2:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
simurgh.cpp:97:17: error: 'end' was not declared in this scope
   97 |  for (auto &i : fin) {
      |                 ^~~
simurgh.cpp:97:17: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from simurgh.cpp:2:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from simurgh.cpp:2:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~