제출 #721132

#제출 시각아이디문제언어결과실행 시간메모리
721132Jarif_Rahman열쇠 (IOI21_keys)C++17
67 / 100
3040 ms52956 KiB
#include "keys.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; struct dsu{ int n; vector<int> sz, p; vector<bool> bl; dsu(int _n): n(_n){ sz.resize(n, 1); bl.assign(n, 0); p.resize(n); for(int i = 0; i < n; i++) p[i] = i; } int get(int x){ if(p[x] != x) p[x] = get(p[x]); return p[x]; } void unite(int a, int b){ a = get(a), b = get(b); if(a == b) return; if(sz[b] > sz[a]) swap(a, b); sz[a]+=sz[b]; sz[b] = 0; p[b] = a; bl[a] = 1; } void reset_bl(){ bl.assign(n, 0); } }; dsu ds(0); int n, m; vector<int> r; vector<vector<pair<int, int>>> graph; vector<bool> candidate; vector<vector<int>> waiting_list; vector<bool> has_key; vector<bool> bl; void reduce_candidates(int s){ vector<int> has_key_v, waiting_list_v, reachable; has_key[r[s]] = 1; has_key_v.pb(r[s]); queue<int> Q; Q.push(s); while(!Q.empty()){ int nd = Q.front(); Q.pop(); if(bl[nd]) continue; bl[nd] = 1; reachable.pb(nd); if(candidate[nd] && nd != s){ candidate[s] = 0; ds.unite(nd, s); break; } if(!has_key[r[nd]]){ for(int x: waiting_list[r[nd]]) if(!bl[x]) Q.push(x); waiting_list[r[nd]].clear(); has_key[r[nd]] = 1; has_key_v.pb(r[nd]); } for(auto [x, c]: graph[nd]) if(!bl[x]){ if(has_key[c]) Q.push(x); else{ waiting_list[c].pb(x); waiting_list_v.pb(c); } } } for(int x: has_key_v) has_key[x] = 0; for(int x: waiting_list_v) waiting_list[x].clear(); for(int x: reachable) bl[x] = 0; } int P; vector<int> ans, p; void bfs(int s){ vector<int> has_key_v, waiting_list_v, reachable; has_key[r[s]] = 1; has_key_v.pb(r[s]); queue<int> Q; Q.push(s); while(!Q.empty()){ int nd = Q.front(); Q.pop(); if(bl[nd]) continue; bl[nd] = 1; reachable.pb(nd); if(!has_key[r[nd]]){ for(int x: waiting_list[r[nd]]) if(!bl[x]) Q.push(x); waiting_list[r[nd]].clear(); has_key[r[nd]] = 1; has_key_v.pb(r[nd]); } for(auto [x, c]: graph[nd]) if(!bl[x]){ if(has_key[c]) Q.push(x); else{ waiting_list[c].pb(x); waiting_list_v.pb(c); } } } for(int x: has_key_v) has_key[x] = 0; for(int x: waiting_list_v) waiting_list[x].clear(); for(int x: reachable) bl[x] = 0; if(reachable.size() < P){ P = reachable.size(); for(int x: p) ans[x] = 0; p = reachable; for(int x: reachable) ans[x] = 1; } else if(reachable.size() == P){ p.insert(p.begin(), reachable.begin(), reachable.end()); for(int x: reachable) ans[x] = 1; } } vector<int> find_reachable(vector<int> _r, vector<int> U, vector<int> V, vector<int> C){ swap(r, _r); n = r.size(), m = U.size(); graph.resize(n); candidate.assign(n, 1); has_key.assign(n, 0); bl.assign(n, 0); waiting_list.resize(n); ans.resize(n); P = n; ds = dsu(n); for(int i = 0; i < m; i++){ graph[U[i]].pb({V[i], C[i]}); graph[V[i]].pb({U[i], C[i]}); } vector<bool> called(n, 0); vector<int> o(n); for(int i = 0; i < n; i++) o[i] = i; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); shuffle(o.begin(), o.end(), rng); for(int k = 0; k < 100; k++){ for(int s = 0; s < n; s++) if(candidate[o[s]] && !ds.bl[ds.get(o[s])] && !called[o[s]]){ called[o[s]] = 1; reduce_candidates(o[s]); } ds.reset_bl(); } for(int s = 0; s < n; s++) if(candidate[s]) bfs(s); return ans; }

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

keys.cpp: In function 'void bfs(int)':
keys.cpp:122:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  122 |     if(reachable.size() < P){
      |        ~~~~~~~~~~~~~~~~~^~~
keys.cpp:128:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  128 |     else if(reachable.size() == P){
      |             ~~~~~~~~~~~~~~~~~^~~~
#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...