Submission #1048139

#TimeUsernameProblemLanguageResultExecution timeMemory
1048139sonamooKeys (IOI21_keys)C++17
9 / 100
48 ms17236 KiB
#include <bits/stdc++.h>
#define SIZE 2005

using namespace std;

int n , m;
int ret[SIZE] , vis[SIZE] , res;
vector<pair<int,int> > graph[SIZE];
vector<int> wait[SIZE];
int key[SIZE] , chk[SIZE];
queue<int> q;

vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) {
	vector<int> ans(r.size(), 1);
    n = r.size() , m = u.size();
    for (int i = 0; i < m; i++) {
        int a = u[i] , b = v[i];
        graph[a].push_back({b,c[i]}); graph[b].push_back({a,c[i]});
    }

    int mi = 1e9;
    for (int S = 0; S < n; S++) {
        memset(vis , 0 , sizeof(vis));
        memset(key , 0 , sizeof(key));
        memset(chk , 0 , sizeof(chk));
        for (int i = 0; i < n; i++) wait[i].clear();

        q.push(S), key[r[S]]=1, vis[S]=1, res=0;
        while(!q.empty()) {
            int here = q.front(); q.pop();
            res++;
            if (key[r[here]]==0) {
                key[r[here]]=1;
                for (auto t : wait[r[here]]) {
                    q.push(t);
                    vis[t]=1;
                }
            }
            for (auto t : graph[here]) {
                int there = t.first , isp = t.second;
                if (key[isp]==1 && vis[there]==0) {
                    vis[there]=1;
                    q.push(there);
                }
                else {
                    if (chk[there] == 0) {
                        chk[there]=1;
                        wait[isp].push_back(there);
                    }
                }
            }
        }
        ret[S] = res;
        mi = min(mi , res);
    }

    for (int i = 0; i < n; i++) if (ret[i] != mi) ans[i] = 0;

	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...