# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1024228 | Abito | Keys (IOI21_keys) | C++17 | 3054 ms | 36552 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using namespace std;
const int N=3e5+5;
int n,r[N],p[N];
vector<pair<int,int>> adj[N],c[N];
bool vis[N],key[N];
void getp(int s){
for (int i=0;i<n;i++) vis[i]=0,key[i]=0;
vis[s]=1;
queue<int> q;q.push(s);
while (!q.empty()){
p[s]++;
int x=q.front();
q.pop();
if (!key[r[x]]){
key[r[x]]=1;
for (auto u:c[r[x]]){
if (vis[u.F]==vis[u.S]) continue;
if (vis[u.F]){
vis[u.S]=1;
q.push(u.S);
}
else{
vis[u.F]=1;
q.push(u.F);
}
}
}
for (auto u:adj[x]){
if (vis[u.F] || !key[u.S]) continue;
vis[u.F]=1;
q.push(u.F);
}
}return;
}
std::vector<int> find_reachable(std::vector<int> R, std::vector<int> U, std::vector<int> V, std::vector<int> C) {
n=R.size();
vector<int> ans(n);
for (int i=0;i<U.size();i++){
adj[U[i]].pb({V[i],C[i]});
adj[V[i]].pb({U[i],C[i]});
c[C[i]].pb({U[i],V[i]});
}
for (int i=0;i<n;i++) r[i]=R[i];
int mn=INT_MAX;
for (int i=0;i<n;i++){
getp(i);
mn=min(p[i],mn);
}
for (int i=0;i<n;i++) ans[i]=(p[i]==mn);
return ans;
}
Compilation message (stderr)
# | 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... |