제출 #974591

#제출 시각아이디문제언어결과실행 시간메모리
974591onlk97열쇠 (IOI21_keys)C++17
9 / 100
3016 ms22868 KiB
#include <vector>
#include <bits/stdc++.h>
using namespace std;
vector <int> find_reachable(vector <int> r,vector <int> u,vector <int> v,vector <int> c){
    int n=r.size(),m=u.size();
    vector <pair <int,int> > g[n];
    for (int i=0; i<m; i++){
        g[u[i]].push_back({v[i],c[i]});
        g[v[i]].push_back({u[i],c[i]});
    }
    vector <int> p,w[n];
    bool have[n],visited[n];
    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++) w[j].clear();
        for (int j=0; j<n; j++) have[j]=0;
        for (int j=0; j<n; j++) visited[j]=0;
        queue <int> q;
        q.push(i);
        have[r[i]]=1;
        visited[i]=1;
        while (!q.empty()){
            int tp=q.front(); q.pop();
            for (auto j:g[tp]){
                if (visited[j.first]) continue;
                if (have[j.second]){
                    visited[j.first]=1;
                    q.push(j.first);
                    if (!have[r[j.first]]){
                        for (int k:w[r[j.first]]){
                            if (!visited[k]){
                                q.push(k);
                                visited[k]=1;
                            }
                        }
                    }
                    have[r[j.first]]=1;
                } else w[j.second].push_back(j.first);
            }
        }
        int cnt=0;
        for (int j=0; j<n; j++){
            if (visited[j]) cnt++;
        }
        p.push_back(cnt);
    }
    int mn=*min_element(p.begin(),p.end());
    vector <int> ans(n,0);
    for (int i=0; i<n; i++){
        if (p[i]==mn) ans[i]=1;
    }
    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...