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>
#define ff first
#define ss second
#define int long long
using namespace std;
typedef pair<int, int> pii;
const int maxn = 3e5 + 10;
int n, m;
pii v_[maxn], v[maxn];
bool mark[maxn];
int32_t main(){
ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> m;
for(int i=1;i<n;i++){
int a, b;
cin >> a >> b;
}
for(int i=1;i<=m;i++)
cin >> v_[i].ff >> v_[i].ss;
sort(v_+1, v_+m+1);
int k=1;
v[k] = v_[k];
for(int i=2;i<=m;i++){
if(v[i].ff <= v[k].ss && v_[i].ss <= v[k].ss) continue;
else if(v[i].ff <= v[k].ss) v[k].ss = v_[i].ss;
else v[++k] = v_[i];
}
m = k;
int ans=(n-1-m)*2*m;
cout << ans << "\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... |
# | 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... |