#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();
}
}
if(n > 100)
return 0;
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 |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
424 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
5 |
Correct |
4 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
1264 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
5104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2115 ms |
257256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2110 ms |
257256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |