답안 #1043330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043330 2024-08-04T08:21:01 Z amirhoseinfar1385 열쇠 (IOI21_keys) C++17
9 / 100
114 ms 70284 KB
#include <vector>
#include<bits/stdc++.h>
using namespace std;
const int maxn=300000+10;
vector<int>revadj[maxn],adj[maxn],allc[maxn],adjs[maxn];
int all[maxn],vis2[maxn],vis[maxn],n,m,par[maxn],nago[maxn];
vector<int>res;
deque<int>allv;

void dfs(int u){
	vis[u]=1;
	for(auto x:adj[u]){
		if(vis[x]==0){
			dfs(x);
		}
	}
	allv.push_front(u);
}

void sfd(int u,int had){
	vis2[u]=1;
	allc[had].push_back(u);
	par[u]=had;
	for(auto x:revadj[u]){
		if(vis2[x]==0){
			sfd(x,had);
		}
	}
}

void calcscc(){
	for(int i=0;i<n;i++){
		if(vis[i]==0){
			dfs(i);
		}
	}
	while((int)allv.size()>0){
		if(vis2[allv.front()]==0){
			sfd(allv.front(),allv.front());
		//	cout<<"hey: "<<allv.front()<<endl;
		//	for(auto x:allc[allv.front()]){
		//		cout<<x<<" ";
		//	}
		//	cout<<endl;
		}
		allv.pop_front();
	}
}

void calres(){
	for(int i=0;i<n;i++){
		for(auto x:adj[i]){
			if(par[i]!=par[x]){
				nago[par[i]]=1;
			}
		}
	}
	int mainres=n+1;
	for(int i=0;i<n;i++){
		if(par[i]==i&&nago[i]==0){
			mainres=min(mainres,(int)allc[i].size());
		}
	}
	for(int i=0;i<n;i++){
		if((int)allc[i].size()==mainres&&par[i]==i&&nago[i]==0){
			for(auto x:allc[i]){
				res[x]=1;
			}
		}	
	}
}

std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) {
	n=(int)r.size();
	m=(int)u.size();
	res.resize(n);
	for(int i=0;i<n;i++){
		all[i]=r[i];
	}
	for(int i=0;i<m;i++){
		if(all[u[i]]==c[i]){
			adj[u[i]].push_back(v[i]);
			revadj[v[i]].push_back(u[i]);
		}
		if(all[v[i]]==c[i]){
			adj[v[i]].push_back(u[i]);
			revadj[u[i]].push_back(v[i]);
		}
	}
	calcscc();
	calres();
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 28504 KB Output is correct
2 Correct 10 ms 28508 KB Output is correct
3 Correct 9 ms 28508 KB Output is correct
4 Correct 11 ms 28508 KB Output is correct
5 Correct 10 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 10 ms 28508 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 11 ms 28508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 28504 KB Output is correct
2 Correct 10 ms 28508 KB Output is correct
3 Correct 9 ms 28508 KB Output is correct
4 Correct 11 ms 28508 KB Output is correct
5 Correct 10 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 10 ms 28508 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 11 ms 28508 KB Output is correct
10 Correct 12 ms 28504 KB Output is correct
11 Correct 10 ms 28588 KB Output is correct
12 Correct 10 ms 28508 KB Output is correct
13 Correct 11 ms 28508 KB Output is correct
14 Correct 9 ms 28508 KB Output is correct
15 Correct 10 ms 28504 KB Output is correct
16 Correct 11 ms 28508 KB Output is correct
17 Incorrect 9 ms 28508 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 28504 KB Output is correct
2 Correct 10 ms 28508 KB Output is correct
3 Correct 9 ms 28508 KB Output is correct
4 Correct 11 ms 28508 KB Output is correct
5 Correct 10 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 10 ms 28508 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 11 ms 28508 KB Output is correct
10 Correct 12 ms 28504 KB Output is correct
11 Correct 10 ms 28588 KB Output is correct
12 Correct 10 ms 28508 KB Output is correct
13 Correct 11 ms 28508 KB Output is correct
14 Correct 9 ms 28508 KB Output is correct
15 Correct 10 ms 28504 KB Output is correct
16 Correct 11 ms 28508 KB Output is correct
17 Incorrect 9 ms 28508 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 28504 KB Output is correct
2 Correct 10 ms 28508 KB Output is correct
3 Correct 9 ms 28508 KB Output is correct
4 Correct 11 ms 28508 KB Output is correct
5 Correct 10 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 10 ms 28508 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 11 ms 28508 KB Output is correct
10 Correct 83 ms 51564 KB Output is correct
11 Incorrect 114 ms 70284 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 28504 KB Output is correct
2 Correct 10 ms 28508 KB Output is correct
3 Correct 9 ms 28508 KB Output is correct
4 Correct 11 ms 28508 KB Output is correct
5 Correct 10 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 10 ms 28508 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 11 ms 28508 KB Output is correct
10 Correct 12 ms 28504 KB Output is correct
11 Correct 10 ms 28588 KB Output is correct
12 Correct 10 ms 28508 KB Output is correct
13 Correct 11 ms 28508 KB Output is correct
14 Correct 9 ms 28508 KB Output is correct
15 Correct 10 ms 28504 KB Output is correct
16 Correct 11 ms 28508 KB Output is correct
17 Incorrect 9 ms 28508 KB Output isn't correct
18 Halted 0 ms 0 KB -