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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 250000 + 7;
const int A = 2500 + 7;
int n;
int r[N];
int c[N];
vector<int> g[N];
int d[N];
bool in_one_step(int a, int b)
{
return (r[a] < r[b] && c[a] < c[b]) || (r[a] > r[b] && c[a] > c[b]);
}
void addEdge(int a, int b)
{
g[a].push_back(b);
g[b].push_back(a);
}
int main()
{
#ifdef ONPC
freopen ("input.txt", "r", stdin);
#endif // ONPC
#ifndef ONPC
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif // ONPC
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> r[i] >> c[i];
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i != j && in_one_step(i, j))
{
addEdge(i, j);
}
}
}
for (int s = 1; s <= n; s++)
{
for (int i = 1; i <= n; i++)
{
d[i] = -1;
}
queue<int> q;
q.push(s);
d[s] = 0;
ll sum = 0;
while (!q.empty())
{
int a = q.front();
q.pop();
sum += d[a];
for (auto &b : g[a])
{
if (d[b] == -1)
{
q.push(b);
d[b] = 1 + d[a];
}
}
}
cout << sum << "\n";
}
return 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... |