이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
vector<ii>exo[2005];
bool v[2005]; ///keys
ll p[2005];
ll siz[2005];
ll find_par(ll a){
if(p[a] == a){
return a;
}
return p[a] = find_par(p[a]);
}
void enose(ll a,ll b){
ll p1 = find_par(a);
ll p2 = find_par(b);
if(p1 != p2){
p[p1] = p2;
siz[p2] += siz[p1];
siz[p1] = 0;
}
}
std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) {
std::vector<int> ans(r.size(), 1);
ll n = r.size();
ll m = u.size();
f(i,0,m){
exo[c[i]].pb(ii(u[i],v[i]));
}
ll timi[n];
ll mini = n + 100;
f(i,0,n){
f(j,0,n){
v[j] = 0;
p[j] = j;
siz[j] = 1;
}
queue<ll>q;
v[r[i]] = 1;
q.push(r[i]);
while(!q.empty()){
ll f = q.front();
q.pop();
for(auto x:exo[f]){
enose(x.F,x.S);
if(!v[r[x.F]]){
v[r[x.F]] = 1;
q.push(r[x.F]);
}
if(!v[r[x.S]]){
v[r[x.S]] = 1;
q.push(r[x.S]);
}
}
}
timi[i] = siz[find_par(i)];
mini = min(mini,timi[i]);
}
f(i,0,n){
if(timi[i] != mini){
ans[i] = 0;
}
}
return ans;
}
# | 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... |