이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifndef WAIMAI
#include "keys.h"
#endif
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 3e5 + 5;
int n;
int r[SIZE], a[SIZE];
vector<pair<int, int>> adj[SIZE];
int to[SIZE];
int dsu(int x) {
return x == to[x] ? x : (to[x] = dsu(to[x]));
}
vector<int> deal(int s, bool is = 0) {
unordered_set<int> us, vs;
unordered_map<int, vector<int>> mp;
queue<int> q;
q.push(s);
vs.insert(s);
while (q.size()) {
int pos = q.front();
q.pop();
if (!us.count(r[pos])) {
us.insert(r[pos]);
for (int x : mp[r[pos]]) {
if (dsu(x) != s) return vector<int>(1, dsu(x));
q.push(x);
vs.insert(x);
}
mp[r[pos]].clear();
}
for (auto [np, c] : adj[pos]) if (!vs.count(np)) {
if (us.count(c)) {
if (dsu(np) != s) return vector<int>(1, dsu(np));
q.push(np);
vs.insert(np);
} else {
mp[c].emplace_back(np);
}
}
}
if (!is) return vector<int>(1, -1);
vector<int> all;
for (int x : vs) all.pb(x);
return all;
}
vector<int> find_reachable(vector<int> _r, vector<int> u, vector<int> v, vector<int> c) {
n = _r.size();
FOR (i, 0, n - 1) {
r[i] = _r[i];
to[i] = i;
}
FOR (i, 0, u.size() - 1) {
adj[u[i]].pb(v[i], c[i]);
adj[v[i]].pb(u[i], c[i]);
}
while (true) {
FOR (i, 0, n - 1) if (dsu(i) == i) a[i] = deal(i)[0];
bool f = 0;
FOR (i, 0, n - 1) if (dsu(i) == i && a[i] != -1) {
to[i] = dsu(a[i]);
f = 1;
}
if (!f) break;
}
int mn = n + 1;
vector<int> ansp, ans(n);
FOR (i, 0, n - 1) if (dsu(i) == i) {
auto v = deal(i, 1);
if (v.size() < mn) {
mn = v.size();
ansp.clear();
}
if (v.size() == mn) ansp.insert(ansp.end(), v.begin(), v.end());
}
for (int x : ansp) ans[x] = 1;
return ans;
}
#ifdef WAIMAI
int main() {
int n, m;
assert(2 == scanf("%d%d", &n, &m));
vector<int> r(n), u(m), v(m), c(m);
for(int i=0; i<n; i++) {
assert(1 == scanf("%d", &r[i]));
}
for(int i=0; i<m; i++) {
assert(3 == scanf("%d %d %d", &u[i], &v[i], &c[i]));
}
vector<int> ans = find_reachable(r, u, v, c);
for (int i = 0; i < (int) ans.size(); ++i) {
if(i) putchar(' ');
putchar(ans[i]+'0');
}
printf("\n");
return 0;
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:94:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
94 | if (v.size() < mn) {
| ~~~~~~~~~^~~~
keys.cpp:98:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
98 | if (v.size() == mn) ansp.insert(ansp.end(), v.begin(), v.end());
| ~~~~~~~~~^~~~~
# | 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... |