Submission #983026

#TimeUsernameProblemLanguageResultExecution timeMemory
983026Faisal_SaqibGame (APIO22_game)C++17
0 / 100
1 ms1112 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define vll vector<ll> int n,k; const int N=3e4+10; bool vis[N]; vector<int> adj[N]; void init(int Q, int P) { n=Q; k=P; for(int i=0;(i+1)<k;i++) adj[i].push_back(i+1); } bool cycle=0; vector<int> path; void dfs(int x,int p=-1) { path.push_back(x); // cout<<x<<' '<<p<<endl; vis[x]=1; for(auto y:adj[x]) { if(!vis[y]) { dfs(y,x); if(cycle) return; } else{ // 0 4 3 y 1 8 9 7 6 .. 2 y // | | // this is a cycle // vll ex={y}; while(path.back()!=y) { ex.pb(path.back()); path.pop_back(); } for(auto lp:ex) { if(lp<k) { cycle=1; return; } } while(ex.size()) { path.pb(ex.back()); ex.pop_back(); } } } path.pop_back(); } int add_teleporter(int u, int v) { adj[u].push_back(v); for(int sp=0;sp<k;sp++) { memset(vis,0,sizeof(vis)); if(!vis[sp]) { path.clear(); cycle=0; dfs(sp); if(cycle) { return 1; } } } return 0; }
#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...