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;
#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vii graph(n,vi());
vector<pair<pair<int,int>,int> > cord (n);
vector<int> r(n);
vector<int> c(n);
for(int i = 0; i < n; i++) {
cin >> r[i] >> c[i];
cord[i] = {{r[i],c[i]},i};
}
sort(cord.begin(),cord.end());
set<pair<int,int> > was;
vi toins;
for(int i = 0; i < n; i++) {
toins.push_back(cord[i].second);
for(auto el : was) {
if(el.first >= cord[i].first.second) {
break;
}
graph[cord[i].second].push_back(el.second);
graph[el.second].push_back(cord[i].second);
}
if(i != n-1 && cord[i+1].first.first > cord[i].first.first) {
for(int el : toins) {
was.insert({c[el],el});
}
toins.clear();
}
}
for(int i = 0; i < n; i++) {
vector<int> dist (n,-1);
queue<int> q;
dist[i] = 0;
q.push(i);
ll sum = 0;
while(!q.empty()) {
int v = q.front();
q.pop();
sum+= dist[v];
for(int u : graph[v]) {
if(dist[u] == -1) {
dist[u] = dist[v]+1;
q.push(u);
}
}
}
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... |