제출 #742857

#제출 시각아이디문제언어결과실행 시간메모리
742857t6twotwo열쇠 (IOI21_keys)C++17
37 / 100
174 ms34100 KiB
#include "keys.h" #include <bits/stdc++.h> using namespace std; vector<int> get(vector<int> p) { int mn = *min_element(p.begin(), p.end()); vector<int> ans(p.size()); for (int i = 0; i < p.size(); i++) { ans[i] = p[i] == mn; } return ans; } std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) { int n = r.size(); int m = c.size(); vector<vector<pair<int, int>>> adj(n); for (int i = 0; i < m; i++) { adj[u[i]].emplace_back(v[i], c[i]); adj[v[i]].emplace_back(u[i], c[i]); } if (c == vector<int>(m, 0)) { vector<int> p(n); for (int i = 0; i < n; i++) { if (r[i] != 0) { p[i] = 1; continue; } vector<bool> vis(n); queue<int> q; vis[i] = 1; q.push(i); while (!q.empty()) { int x = q.front(); q.pop(); p[i]++; for (auto [y, z] : adj[x]) { if (!vis[y]) { vis[y] = 1; q.push(y); } } } } return get(p); } if (n <= 2000 && m <= 2000) { vector<int> p(n); for (int i = 0; i < n; i++) { vector<bool> vis(n); vector<bool> have(n); vector<vector<int>> w(n); queue<int> q; vis[i] = 1; q.push(i); while (!q.empty()) { int x = q.front(); q.pop(); p[i]++; have[r[x]] = 1; for (int v : w[r[x]]) { if (!vis[v]) { vis[v] = 1; q.push(v); } } for (auto [y, z] : adj[x]) { if (have[z]) { if (!vis[y]) { vis[y] = 1; q.push(y); for (int v : w[r[y]]) { if (!vis[v]) { vis[v] = 1; q.push(v); } } w[r[y]].clear(); } } else { w[z].push_back(y); } } } } return get(p); } }

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

keys.cpp: In function 'std::vector<int> get(std::vector<int>)':
keys.cpp:7:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |  for (int i = 0; i < p.size(); i++) {
      |                  ~~^~~~~~~~~~
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:15:38: warning: control reaches end of non-void function [-Wreturn-type]
   15 |  vector<vector<pair<int, int>>> adj(n);
      |                                      ^
#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...