이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "keys.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> find_reachable(vector<int> r, vector<int> U, vector<int> V, vector<int> C) {
int n = r.size(), mn = INT_MAX;
vector<vector<array<int, 2>>> G(n);
for (int i = 0; i < U.size(); i++) {
G[U[i]].push_back({V[i], C[i]});
G[V[i]].push_back({U[i], C[i]});
}
vector<int> ans, perm(n), pos(n), cnt(n), vis(n, -1), visc(n, -1);
vector<vector<int>> cand(n);
vector<bool> solved(n);
iota(perm.begin(), perm.end(), 0);
for (int i = 0; i < n; i++) {
for (auto &e : G[i]) cnt[i] += e[1] == r[i];
}
sort(perm.begin(), perm.end(), [&](int u, int v) { return cnt[u] < cnt[v]; });
for (int i = 0; i < n; i++) {
pos[perm[i]] = i;
}
for (int i = 0; i < n; i++) {
sort(G[i].begin(), G[i].end(), [&](array<int, 2> p, array<int, 2> q) { return pos[p[0]] < pos[q[0]]; });
}
queue<int> Q;
vector<int> ver, col;
for (int x : perm) {
ver = {x}, col.clear();
while (!Q.empty()) Q.pop();
Q.push(x), vis[x] = x, solved[x] = 1;
while (!Q.empty()) {
int u = Q.front(); Q.pop();
if (visc[r[u]] ^ x) {
for (int v : cand[r[u]]) if (vis[v] ^ x) {
ver.push_back(v), Q.push(v), vis[v] = x;
if (solved[v] || ver.size() > mn) goto nxt;
}
visc[r[u]] = x;
}
for (auto &e : G[u]) if (vis[e[0]] ^ x) {
if (visc[e[1]] == x) {
ver.push_back(e[0]), Q.push(e[0]), vis[e[0]] = x;
if (solved[e[0]] || ver.size() > mn) goto nxt;
} else {
col.push_back(e[1]);
if (solved[e[0]]) cand[e[1]].clear();
cand[e[1]].push_back(e[0]);
}
}
}
if (ver.size() < mn) mn = ver.size(), ans = ver;
else copy(ver.begin(), ver.end(), back_inserter(ans));
nxt:
for (int c : col) cand[c].clear();
}
vector<int> res(n);
for (int x : ans) res[x] = 1;
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:8:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | for (int i = 0; i < U.size(); i++) {
| ~~^~~~~~~~~~
keys.cpp:37:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
37 | if (solved[v] || ver.size() > mn) goto nxt;
| ~~~~~~~~~~~^~~~
keys.cpp:44:37: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
44 | if (solved[e[0]] || ver.size() > mn) goto nxt;
| ~~~~~~~~~~~^~~~
keys.cpp:52:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
52 | if (ver.size() < mn) mn = ver.size(), ans = ver;
| ~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |