This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
int n,k;
typedef pair<int,int> ii;
#define ff first
#define ss second
const int maxn = 3e5 + 10;
vector <int> adj[maxn];
int l[maxn],t[maxn],cnt,num[maxn];
int scc,id[maxn];
stack<int> st;
bool dau[maxn];
void dfs(int x)
{
st.push(x);
l[x]=t[x]=++cnt;
for (int i:adj[x])
if (!dau[i])
{
if (t[i]==0)
{
dfs(i);
l[x]=min(l[x],l[i]);
}
else l[x]=min(l[x],t[i]);
}
if (l[x]==t[x])
{
int temp; scc++;
do
{
temp=st.top(); st.pop();
dau[temp]=1;
id[temp]=scc;
}
while (temp!=x);
}
}
bool check()
{
for (int i=1; i<=n; i++) l[i]=t[i]=dau[i]=id[i]=num[i]=0;
while (!st.empty()) st.pop();
cnt=scc=0;
for (int i=1; i<=n; i++) if (!t[i]) dfs(i);
for (int i=1; i<=n; i++)
for (int j:adj[i])
if (id[i]==id[j]) num[id[i]]++;
for (int i=1; i<=k; i++) if (num[id[i]]>0) return 1;
return 0;
}
void init(int N, int K) {
n=N; k=K;
for (int i=1; i<=n; i++) adj[i].clear();
for (int i=2; i<=k; i++) adj[i-1].push_back(i);
}
int add_teleporter(int u, int v) {
u++; v++;
adj[u].push_back(v);
return check();
}
Compilation message (stderr)
game.cpp: In function 'bool check()':
game.cpp:45:52: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
45 | for (int i=1; i<=n; i++) l[i]=t[i]=dau[i]=id[i]=num[i]=0;
| ~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |