RE on #4,6,7,8,9,10
TLE on #5
#include<bits/stdc++.h>
using namespace std;
const int maxn = 4005;
struct edge
{
int to,nxt;
}e[maxn << 1],e2[maxn << 1];
int head[maxn],tot;
int head2[maxn],tot2;
void add_edge(int u,int v)
{
e[++tot].nxt = head[u];
head[u] = tot;
e[tot].to = v;
}
void add_edge2(int u,int v)
{
e2[++tot2].nxt = head2[u];
head2[u] = tot2;
e2[tot2].to = v;
}
int dfn[maxn],low[maxn],tim;
int col[maxn],in[maxn];
int stk[maxn],top;
int ins[maxn];
bitset<maxn> S[maxn];
int cnt;
void tarjan(int u)
{
dfn[u] = low[u] = ++tim;
stk[++top] = u;
for(int i = head[u];i;i = e[i].nxt)
{
int v = e[i].to;
if(!dfn[v])
{
tarjan(v);
low[u] = min(low[u],low[v]);
}
else if(!col[v])
{
low[u] = min(low[u],dfn[v]);
}
}
if(dfn[u] == low[u])
{
col[u] = ++cnt;
do
{
col[stk[top]] = col[u];
S[cnt].set(stk[top]);
}while(stk[top--] != u);
}
}
int n;
int p[maxn],d[maxn];
bool con[maxn][maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1;i <= n;i++)
{
cin >> p[i] >> d[i];
}
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= n;j++)
{
if(abs(p[i] - p[j]) <= d[i])
{
add_edge(i,j);
}
}
}
for(int i = 1;i <= n;i++)
{
if(!dfn[i])
{
tarjan(i);
}
}
for(int i = 1;i <= n;i++)
{
for(int j = head[i];j;j = e[j].nxt)
{
int v = e[j].to;
if(col[i] == col[v] || con[col[i]][col[v]])
{
continue;
}
add_edge2(col[i],col[v]);
con[col[i]][col[v]] = 1;
in[col[v]]++;
}
}
queue<int> q;
for(int i = 1;i <= cnt;i++)
{
if(!in[i])
{
q.push(i);
}
}
while(!q.empty())
{
int u = q.front();
q.pop();
for(int i = head2[u];i;i = e2[i].nxt)
{
int v = e2[i].to;
S[v] |= S[u];
in[v]--;
if(!in[v])
{
q.push(v);
}
}
}
double ans = 0;
// for(int i = 1;i <= n;i++)
// {
// ans += 1.0 / ((int)(S[col[i]].count()));
// }
// for(int i = 1;i <= cnt;i++)
// {
// cout << (int)(S[i].count()) << '\n';
// }
printf("%.4lf",ans);
return 0;
}