이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i)
#define RFOR(i, x, n) for (ll i =x; i>=n; --i)
using namespace std;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> piii;
ll par[300005];
ll find(ll x) {return ((par[x]==x)?x:par[x] = find(par[x]));}
void unite(ll from, ll to) {par[find(from)] = find(to);}
ll siz = LLONG_MAX;
vector<ll> minn, now,lock1;
vector<bool> visited;
vector<ll> onlock[300005];
ll havekey[300005], prevv[300005], key[300005], fin[300005];
vector<pi> adj[300005];
void del()
{
for (ll u: now) havekey[key[u]] = 0;
for (ll u: lock1) onlock[u].clear();
now.clear(); lock1.clear();
}
void bfs(ll from, ll t)
{
prevv[from] = t;
queue<ll> q;
q.push(from);
while (q.size())
{
ll c = q.front();
q.pop();
if (find(c) != find(from))
{
// c will lead to better result
// terminate
unite(from,c);
prevv[find(c)] = t;
del();
return;
}
if (visited[c]) continue;
visited[c] = 1;
now.pb(c);
if (!havekey[key[c]])
{
havekey[key[c]] = 1;
for (ll u: onlock[key[c]]) q.push(u);
onlock[key[c]].clear();
}
for (pi u: adj[c])
{
if (havekey[u.s])
{
q.push(u.f);
}
else
{
lock1.pb(u.s);
onlock[u.s].pb(u.f);
}
}
}
fin[from] = 1;
if (siz > now.size())
{
siz = now.size();
minn = now;
}
else if (siz == now.size())
{
for (ll u: now) minn.pb(u);
}
del();
}
std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c)
{
ll n = r.size(), m = u.size();
for (ll i=0; i<m; ++i) havekey[i] = 0;
for (ll i=0; i<n; ++i) par[i] = i, key[i] = r[i], fin[i] = prevv[i] = 0;
for (ll i=0; i<m; ++i)
{
adj[u[i]].pb(mp(v[i], c[i]));
adj[v[i]].pb(mp(u[i], c[i]));
}
// bfs
ll t = 1;
bool done = 0;
while (!done)
{
done = 1;
visited.assign(n, 0);
for (ll i=0; i<n; ++i)
{
if (find(i)==i && !fin[i] && prevv[i]!=t)
{
bfs(i, t);
done = 0;
}
}
t++;
}
vector<int> ans(n, 0);
for (ll u: minn) ans[u] = 1;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
keys.cpp: In function 'void bfs(ll, ll)':
keys.cpp:98:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | if (siz > now.size())
| ~~~~^~~~~~~~~~~~
keys.cpp:103:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | else if (siz == now.size())
| ~~~~^~~~~~~~~~~~~
# | 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... |