제출 #629556

#제출 시각아이디문제언어결과실행 시간메모리
629556hy_1열쇠 (IOI21_keys)C++17
0 / 100
4 ms7252 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 > i : 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> hhh; vector<vector<int> > key(r.size() , hhh); vector<int> visited(r.size() , false); for(int jj =0; jj <r.size(); jj++){ int source = jj; queue<int> qu; if(visited[source] == false){ qu.push(source); vector<int> stock; visited[source] = false; stock.push_back(r[source]); 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, vector<int> > yyy = dfs(r , i.first , adj , stock); dp[i.first] = yyy.first; key[i.first] = yyy.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::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:86:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |  for(int jj =0; jj <r.size(); jj++){
      |                 ~~~^~~~~~~~~
keys.cpp:115:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |  for(int i =0; i <dp.size(); i++){
      |                ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...