Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- I am Hunting High and Low
- Diving from the sky above
- Looking for, more and more, once again
- I'm Hunting High and Low
- Sometimes I may win, sometimes I'll lose
- It's just a game that I play
- After the storm there's a calm
- Through the clouds shines a ray of the sun
- I'm carried from all my harm
- There is no one I can't outrun
- Now I'm leaving my worries behind
- Feel the freedom of body and mind
- I'm starting my journey, I'm drifting away with the wind, I go___________________:-
- */
- #include <bits/stdc++.h>
- using namespace std;
- /* #include <ext/pb_ds/assoc_container.hpp>
- using namespace __gnu_pbds;
- typedef tree<int,null_type,less<int>,rb_tree_tag,
- tree_order_statistics_node_update> indexed_set; */
- typedef long long ll;
- typedef unsigned long long ull;
- typedef long double ld;
- typedef pair < int , int > pi;
- typedef pair < int64_t , int64_t > pii;
- const int N = 1e5+7;
- int luck[N], vis[N];
- const int32_t mod = 1e9 + 7;
- #define pb(x) push_back(x)
- #define A(s) s.begin(),s.end()
- #define L(x) (int)((x).size())
- #define V vector<int>
- #define VL vector<ll>
- #define S set<int>
- #define SL set<ll>
- #define Ml multiset < int >
- #define ML multiset < ll >
- #define f(i,p,n) for(int i=(p);i<n;i++)
- #define B(v) v.begin()
- #define E(v) v.end()
- #define M map < int , int >
- #define SS second
- #define F first
- vector < V > v(N);
- template <class T> inline void smax(T &x,T y){ x = max((x), (y));}
- template <class T> inline void smin(T &x,T y){ x = min((x), (y));}
- void initializer(int n, int x = 1){
- if(x > n)return;
- luck[x] = 100;
- initializer(n, x + 1);
- }
- int flag = 0;
- // to detect a cycle using dfs
- void Eminem_Lover(int to_p, int check){
- vis[to_p] = true;
- for(auto it : v[to_p]){
- if(!vis[it]){
- Eminem_Lover(it, to_p);
- }
- else if(vis[it] && it != check)flag = 1;//Cycle detected
- }// check ki condition mandatory h ........... otherwise Jaha se call aayi h usi ko manke cycle bataa dega
- }
- ll expo(ll x, ll n, ll mod){
- ll res = 1LL;
- while(n){
- if(n & 1) res = (res * x) % mod;
- x = (x * x) % mod;
- n = n / 2;
- }
- return res;
- }
- int main(){
- ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
- #ifndef ONLINE_JUDGE
- // freopen("in.txt", "r", stdin);
- // freopen("out.txt", "w", stdout);
- #endif
- int i, j, k, l, r, cnt1 = 0, cnt2 = 0;
- // Begin:-
- int n;
- cin >> n;
- f(i,0,n-1)cin >> l >> r, v[l].pb(r), v[r].pb(l);
- initializer(n);
- Eminem_Lover(3, 3);// Kisi b root ki adjacancy list me vahi element to present hoga nahi
- // isliye for first time Root ko hi check banaa k bhej diya h
- // Ho skta h glt ho logic.............. mgr lg to theek hi rha h
- cout << flag;
- return 0;
- }
Add Comment
Please, Sign In to add comment