# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
894832 | MuhammadSaram | Keys (IOI21_keys) | C++17 | 73 ms | 16416 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>
using namespace std;
const int M = 2000;
vector<pair<int,int>> nei[M];
bool vis[M];
int bfs(int u,vector<int> r)
{
vis[u]=true;
set<int> se;
se.insert(r[u]);
queue<int> q;
q.push(u);
while (!q.empty())
{
int x=q.front();
q.pop();
for (auto i:nei[x])
if (!vis[i.first] and se.find(i.second)!=se.end())
{
vis[i.first]=true;
q.push(i.first);
se.insert(r[i.first]);
}
}
int ans=0;
for (int i=0;i<r.size();i++)
ans+=(vis[i]);
return ans;
}
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c)
{
int n=r.size();
int m=u.size();
for (int i=0;i<m;i++)
{
nei[u[i]].push_back({v[i],c[i]});
nei[v[i]].push_back({u[i],c[i]});
}
int ans[n];
for (int i=0;i<n;i++)
{
ans[i]=bfs(i,r);
for (int j=0;j<n;j++)
vis[j]=false;
}
vector<int> ans1;
for (int i=0;i<n;i++)
{
ans1.push_back(1);
for (int j=0;j<n;j++)
if (ans[i]>ans[j])
{
ans1[i]=0;
break;
}
}
return ans1;
}
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... |