Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <bits/stdc++.h>
- using namespace std;
- int low[100001];
- int depth[100001];
- int parrent[100001];
- bool ans[100001];
- vector<int> v[100001];
- void dfs(int d, int u){
- depth[u] = low[u] = d;
- for(unsigned i = 0; i < v[u].size(); ++i){
- int cur = v[u][i];
- if(depth[cur] == 0)dfs(d+1, cur);
- if(low[u] > low[cur]){
- low[u] = low[cur];
- parrent[u] = parrent[cur];
- ans[u] = ans[parrent[u]] = 1;
- }
- }
- }
- int main(){
- int n,m;
- cin >> n >> m;
- for(int i = 0; i < m; ++i){
- int a,b;
- cin >> a >> b;
- v[a].emplace_back(b);
- }
- for(int i = 1; i <= n; ++i)parrent[i] = i;
- for(int i = 1; i <= n; ++i){
- if(depth[i] == 0)dfs(1, i);
- }
- for(int i = 1; i <= n; ++i){
- if(i != 1)cout << ' ';
- cout << ans[i];
- }
- cout << '\n';
- return 0;
- }
Add Comment
Please, Sign In to add comment