이 제출은 이전 버전의 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<ll>exo[2005];
bool vis[2005];
bool visn[2005];
vector<ii>adj[2005];
ll res = 0;
vector<int>R;
void dfs(ll idx){
res++;
visn[idx] = 1;
if(!vis[R[idx]]){
vis[R[idx]] = 1;
for(auto x:exo[R[idx]]){
if(!visn[x]){
dfs(x);
}
}
exo[R[idx]].clear();
}
for(auto x:adj[idx]){
if(vis[x.S]){
if(!visn[x.F]){
dfs(x.F);
}
}
else{
exo[x.S].pb(x.F);
}
}
}
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();
R = r;
f(i,0,m){
adj[u[i]].pb(ii(v[i],c[i]));
adj[v[i]].pb(ii(u[i],c[i]));
}
ll timi[n] = {0};
ll mini = n + 100;
f(i,0,n){
f(j,0,n){
vis[j] = 0;
visn[j] = 0;
exo[j].clear();
}
res = 0;
dfs(i);
timi[i] = res;
mini = min(mini,timi[i]);
}
f(i,0,n){
if(timi[i] != mini){
ans[i] = 0;
}
}
return ans;
}
/*
int main() {
int n, m;
assert(2 == scanf("%d%d", &n, &m));
std::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]));
}
fclose(stdin);
std::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;
}
*/
# | 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... |