Submission #1052998

# Submission time Handle Problem Language Result Execution time Memory
1052998 2024-08-11T07:33:56 Z noyancanturk Keys (IOI21_keys) C++17
37 / 100
3000 ms 42184 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
using pii=pair<int,int>;

const int lim=3e5+100;
int n,m;

vector<pii>v[lim];
bool havekey[lim];
vector<int>willvis[lim],r;
bool vis[lim];

void dfs(int node){
    if(vis[node])return;
    vis[node]=1;
    if(!havekey[r[node]]){
        havekey[r[node]]=1;
        for(int j:willvis[r[node]]){
            dfs(j);
        }
    }
    for(auto[j,c]:v[node]){
        if(havekey[c]){
            dfs(j);
        }else{
            willvis[c].pb(j);
        }
    }
}

vector<int> find_reachable(vector<int> R, vector<int> U, vector<int> V, vector<int> c) {
	n=R.size(),m=U.size();
    r=R;
    for(int i=0;i<m;i++){
        v[U[i]].pb({V[i],c[i]});
        v[V[i]].pb({U[i],c[i]});
    }
	int res=INT_MAX;
	vector<int>ans;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            vis[j]=0;
            havekey[j]=0;
            willvis[j].clear();
        }
        dfs(i);
        int cnt=0;
        for(int j=0;j<n;j++){
            if(vis[j])cnt++;
        }
        if(cnt<res){
            res=cnt;
            ans.clear();
        }
        if(res==cnt){
            ans.pb(i);
        }
    }
	vector<int>finalans(n,0);
	for(int i:ans){
		finalans[i]=1;
	}
	return finalans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14936 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 2 ms 14940 KB Output is correct
5 Correct 2 ms 14940 KB Output is correct
6 Correct 2 ms 14952 KB Output is correct
7 Correct 2 ms 14940 KB Output is correct
8 Correct 2 ms 14940 KB Output is correct
9 Correct 2 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14936 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 2 ms 14940 KB Output is correct
5 Correct 2 ms 14940 KB Output is correct
6 Correct 2 ms 14952 KB Output is correct
7 Correct 2 ms 14940 KB Output is correct
8 Correct 2 ms 14940 KB Output is correct
9 Correct 2 ms 14940 KB Output is correct
10 Correct 2 ms 14940 KB Output is correct
11 Correct 2 ms 14944 KB Output is correct
12 Correct 2 ms 14944 KB Output is correct
13 Correct 2 ms 14948 KB Output is correct
14 Correct 2 ms 14944 KB Output is correct
15 Correct 2 ms 14940 KB Output is correct
16 Correct 2 ms 14940 KB Output is correct
17 Correct 2 ms 14940 KB Output is correct
18 Correct 2 ms 14788 KB Output is correct
19 Correct 2 ms 14940 KB Output is correct
20 Correct 2 ms 14940 KB Output is correct
21 Correct 3 ms 14936 KB Output is correct
22 Correct 2 ms 14940 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 2 ms 14940 KB Output is correct
25 Correct 2 ms 14948 KB Output is correct
26 Correct 2 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14936 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 2 ms 14940 KB Output is correct
5 Correct 2 ms 14940 KB Output is correct
6 Correct 2 ms 14952 KB Output is correct
7 Correct 2 ms 14940 KB Output is correct
8 Correct 2 ms 14940 KB Output is correct
9 Correct 2 ms 14940 KB Output is correct
10 Correct 2 ms 14940 KB Output is correct
11 Correct 2 ms 14944 KB Output is correct
12 Correct 2 ms 14944 KB Output is correct
13 Correct 2 ms 14948 KB Output is correct
14 Correct 2 ms 14944 KB Output is correct
15 Correct 2 ms 14940 KB Output is correct
16 Correct 2 ms 14940 KB Output is correct
17 Correct 2 ms 14940 KB Output is correct
18 Correct 2 ms 14788 KB Output is correct
19 Correct 2 ms 14940 KB Output is correct
20 Correct 2 ms 14940 KB Output is correct
21 Correct 3 ms 14936 KB Output is correct
22 Correct 2 ms 14940 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 2 ms 14940 KB Output is correct
25 Correct 2 ms 14948 KB Output is correct
26 Correct 2 ms 14940 KB Output is correct
27 Correct 23 ms 15448 KB Output is correct
28 Correct 25 ms 15256 KB Output is correct
29 Correct 22 ms 15196 KB Output is correct
30 Correct 10 ms 14936 KB Output is correct
31 Correct 4 ms 14936 KB Output is correct
32 Correct 2 ms 14940 KB Output is correct
33 Correct 3 ms 14940 KB Output is correct
34 Correct 11 ms 15092 KB Output is correct
35 Correct 10 ms 14940 KB Output is correct
36 Correct 42 ms 15216 KB Output is correct
37 Correct 35 ms 15196 KB Output is correct
38 Correct 57 ms 15248 KB Output is correct
39 Correct 55 ms 15240 KB Output is correct
40 Correct 6 ms 14940 KB Output is correct
41 Correct 22 ms 15168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14936 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 2 ms 14940 KB Output is correct
5 Correct 2 ms 14940 KB Output is correct
6 Correct 2 ms 14952 KB Output is correct
7 Correct 2 ms 14940 KB Output is correct
8 Correct 2 ms 14940 KB Output is correct
9 Correct 2 ms 14940 KB Output is correct
10 Execution timed out 3016 ms 42184 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14936 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 2 ms 14940 KB Output is correct
5 Correct 2 ms 14940 KB Output is correct
6 Correct 2 ms 14952 KB Output is correct
7 Correct 2 ms 14940 KB Output is correct
8 Correct 2 ms 14940 KB Output is correct
9 Correct 2 ms 14940 KB Output is correct
10 Correct 2 ms 14940 KB Output is correct
11 Correct 2 ms 14944 KB Output is correct
12 Correct 2 ms 14944 KB Output is correct
13 Correct 2 ms 14948 KB Output is correct
14 Correct 2 ms 14944 KB Output is correct
15 Correct 2 ms 14940 KB Output is correct
16 Correct 2 ms 14940 KB Output is correct
17 Correct 2 ms 14940 KB Output is correct
18 Correct 2 ms 14788 KB Output is correct
19 Correct 2 ms 14940 KB Output is correct
20 Correct 2 ms 14940 KB Output is correct
21 Correct 3 ms 14936 KB Output is correct
22 Correct 2 ms 14940 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 2 ms 14940 KB Output is correct
25 Correct 2 ms 14948 KB Output is correct
26 Correct 2 ms 14940 KB Output is correct
27 Correct 23 ms 15448 KB Output is correct
28 Correct 25 ms 15256 KB Output is correct
29 Correct 22 ms 15196 KB Output is correct
30 Correct 10 ms 14936 KB Output is correct
31 Correct 4 ms 14936 KB Output is correct
32 Correct 2 ms 14940 KB Output is correct
33 Correct 3 ms 14940 KB Output is correct
34 Correct 11 ms 15092 KB Output is correct
35 Correct 10 ms 14940 KB Output is correct
36 Correct 42 ms 15216 KB Output is correct
37 Correct 35 ms 15196 KB Output is correct
38 Correct 57 ms 15248 KB Output is correct
39 Correct 55 ms 15240 KB Output is correct
40 Correct 6 ms 14940 KB Output is correct
41 Correct 22 ms 15168 KB Output is correct
42 Execution timed out 3016 ms 42184 KB Time limit exceeded
43 Halted 0 ms 0 KB -