제출 #629547

#제출 시각아이디문제언어결과실행 시간메모리
629547hy_1열쇠 (IOI21_keys)C++17
컴파일 에러
0 ms0 KiB
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <cmath> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <unordered_map> using namespace std; #define all(x) x.begin(),x.end() const int mx = 300001; pair<int , vector<int > > dfs(vector<int> &r , int source , vector<vector<pair<int , int > > > &adj , vector<int> &stock){ stack<int> st; st.push(source); pair<int , vector<int> > ans; vector<bool> visited(r.size() , false); while(!st.empty()){ int cur = st.top(); st.pop(); visited[cur] = true; for(pair<int ,int > : adj[cur]){ if(count(all(stock) , i.second) != 0){ ans.second.push_back(r[i.first]); stock.push_back(r[i.first]); visited[i.first] = true; st.push(i.first); } } } ans.first = ans.second.size(); return ans; } vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { //Graph implementatiom vector<vector<pair<int , int > > > adj(mx); for(int i=0; i <u.size(); i++){ pair<int, int> vv; vv.first = v[i]; vv.second = c[i]; adj[u[i]].push_back(vv); vv.first = u[i]; vv.second = c[i]; adj[v[i]].push_back(vv); } //BFS vector<int> dp(r.size() , 1); vector<int> visited(r.size() , false); for(int i =0; i <r.size(); i++){ int source = i; queue<int> qu; if(visited[source] == false){ qu.push(source); vector<int> stock(); visited[source] = false; while(!qu.empty()){ int cur = qu.front(); qu.pop(); for(pair<int , int> i : adj[cur]){ if(dp[i.first] != -1 && count(all(stock) , i.second) != 0){ dp[cur] += dp[i.first] + 1; for(int h : key[i.first]) stock.push_back(h); }else{ pair<int, int> yyy = dfs(r , i.first , adj , stock); dp[i.first] = yyy.first; key[i.first] = yy.second; dp[cur] += dp[i.first]+1; key[i.first] = yyy.second; } } } } } vector<int> solution(r.size() , 0); int y = *min_element(all(dp)); for(int i =0; i <dp.size(); i++){ if(dp[i] == y){ solution[i] = 1; }else{ solution[i] = 0; } } return solution; } /* #1 4 0 1 1 2 5 0 0 1 1 3 1 2 2 3 1 0 0 1 0 2 #2 3 0 0 0 1 0 1 0 #3 7 0 1 1 2 2 1 2 10 0 0 1 1 2 3 3 4 4 5 1 2 2 3 3 4 5 5 6 6 0 0 1 0 0 1 2 0 2 1 */ // int main(){ // int n; cin >> n; // vector<int> r(n); // for(int &i : r) cin >> i; // int m; cin >> m; // vector<int> u(m); // vector<int> v(m); // for(int &i : u) cin >> i; // for(int &i : v) cin >> i; // vector<int> c(m); // for(int &i : c) cin >> i; // for(int i =0; i <n; i++){ // vector<int> ans = find_reachable(r , u , v, c); // for(int i :ans){ // cout << i << " "; // } // cout << endl; // } // return 0; // }

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

keys.cpp: In function 'std::pair<int, std::vector<int> > dfs(std::vector<int>&, int, std::vector<std::vector<std::pair<int, int> > >&, std::vector<int>&)':
keys.cpp:54:23: error: expected unqualified-id before ':' token
   54 |   for(pair<int ,int > : adj[cur]){
      |                       ^
keys.cpp:55:26: error: 'i' was not declared in this scope
   55 |    if(count(all(stock) , i.second) != 0){
      |                          ^
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:71:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for(int i=0; i <u.size(); i++){
      |               ~~^~~~~~~~~
keys.cpp:84:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |  for(int i =0; i <r.size(); i++){
      |                ~~^~~~~~~~~
keys.cpp:39:18: error: request for member 'begin' in 'stock', which is of non-class type 'std::vector<int>()'
   39 | #define all(x) x.begin(),x.end()
      |                  ^~~~~
keys.cpp:95:36: note: in expansion of macro 'all'
   95 |      if(dp[i.first] != -1 && count(all(stock) , i.second) != 0){
      |                                    ^~~
keys.cpp:39:28: error: request for member 'end' in 'stock', which is of non-class type 'std::vector<int>()'
   39 | #define all(x) x.begin(),x.end()
      |                            ^~~
keys.cpp:95:36: note: in expansion of macro 'all'
   95 |      if(dp[i.first] != -1 && count(all(stock) , i.second) != 0){
      |                                    ^~~
keys.cpp:97:19: error: 'key' was not declared in this scope; did you mean 'key_t'?
   97 |       for(int h : key[i.first])
      |                   ^~~
      |                   key_t
keys.cpp:98:14: error: request for member 'push_back' in 'stock', which is of non-class type 'std::vector<int>()'
   98 |        stock.push_back(h);
      |              ^~~~~~~~~
keys.cpp:100:52: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::vector<int>()'
  100 |       pair<int, int> yyy = dfs(r , i.first , adj , stock);
      |                                                    ^~~~~
keys.cpp:45:116: note: in passing argument 4 of 'std::pair<int, std::vector<int> > dfs(std::vector<int>&, int, std::vector<std::vector<std::pair<int, int> > >&, std::vector<int>&)'
   45 | pair<int , vector<int > > dfs(vector<int> &r , int source , vector<vector<pair<int , int > > > &adj , vector<int> &stock){
      |                                                                                                       ~~~~~~~~~~~~~^~~~~
keys.cpp:102:7: error: 'key' was not declared in this scope
  102 |       key[i.first] = yy.second;
      |       ^~~
keys.cpp:102:22: error: 'yy' was not declared in this scope; did you mean 'yyy'?
  102 |       key[i.first] = yy.second;
      |                      ^~
      |                      yyy
keys.cpp:112:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |  for(int i =0; i <dp.size(); i++){
      |                ~~^~~~~~~~~~