#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define double long double
#define int long long
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 55;
const int oo = 1e18 + 7, mod = 1e9 + 7;
int n, m, c;
int x[N], y[N];
int a[N], b[N], ccc[N], d[N];
map<int, vector<ii>> mp1, mp2;
vector<pair<int, ii>> edges;
int cc[N], mx[N];
int tol[N];
int sz[N], root[N];
int rt(int x){
return (x == root[x] ? x : rt(x));
}
bool merge(int x, int y){
x = rt(x), y = rt(y);
if(x == y) return 0;
if(sz[x] < sz[y]) swap(x, y);
sz[x] += sz[y];
root[y] = x;
return 1;
}
void process(){
cin >> n >> m >> c;
for(int i = 1; i <= n; i++){
cin >> x[i] >> y[i];
mp1[x[i]].pb({y[i], i});
mp2[y[i]].pb({x[i], i});
}
for(int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> ccc[i] >> d[i];
for(map<int, vector<ii>>::iterator it = mp1.begin(); it != mp1.end(); it++){
vector<ii> temp = (*it).se;
sort(temp.begin(), temp.end());
for(int i = 1; i < temp.size(); i++){
//cout << (*it).fi << " " << temp[i - 1].fi << " " << temp[i].fi << "\n";
bool ck = 1;
for(int j = 1; j <= m; j++){
bool ck2 = 1;
if((*it).fi >= a[j] && (*it).fi <= ccc[j]){}
else ck2 = 0;
if(temp[i - 1].fi > d[j] || temp[i].fi < b[j]) ck2 = 0;
if(ck2) ck = 0;
}
if(!ck) continue;
//cout << (*it).fi << " " << temp[i - 1].fi << " " << temp[i].fi << "\n";
//cout << "1 " << temp[i].se << " " << temp[i - 1].se << "\n";
edges.pb({temp[i].fi - temp[i - 1].fi, {temp[i].se, temp[i - 1].se}});
}
}
for(map<int, vector<ii>>::iterator it = mp2.begin(); it != mp2.end(); it++){
vector<ii> temp = (*it).se;
sort(temp.begin(), temp.end());
for(int i = 1; i < temp.size(); i++){
//cout << (*it).fi << " " << temp[i - 1].fi << " " << temp[i].fi << "\n";
bool ck = 1;
for(int j = 1; j <= m; j++){
bool ck2 = 1;
if((*it).fi >= b[j] && (*it).fi <= d[j]){}
else ck2 = 0;
if(temp[i - 1].fi > ccc[j] || temp[i].fi < a[j]) ck2 = 0;
if(ck2) ck = 0;
}
if(!ck) continue;
//cout << (*it).fi << " " << temp[i - 1].fi << " " << temp[i].fi << "\n";
//cout << "2 " << (*it).fi << " " << temp[i].se << " " << temp[i - 1].se << "\n";
edges.pb({temp[i].fi - temp[i - 1].fi, {temp[i].se, temp[i - 1].se}});
}
}
//return;
sort(edges.begin(), edges.end());
int cnt = n;
for(int i = 1; i <= n; i++){
sz[i] = 1, root[i] = i;
}
for(auto it : edges){
//cout << it.se.fi << " " << it.se.se << "\n";
//continue;
if(merge(it.se.fi, it.se.se)){
cnt--;
assert(cnt >= 0);
tol[cnt] = tol[cnt + 1] + it.fi;
//cout << cnt << " " << tol[cnt] << "\n";
}
}
//return;
for(int i = 0; i < cnt; i++) tol[i] = oo;
//for(int i = 0; i <= n; i++) cout << tol[i] << "\n";
for(int i = 1; i <= c; i++){
cin >> cc[i] >> mx[i];
int answer = oo;
for(int j = 0; j <= mx[i]; j++) answer = min(answer, cc[i] * j + tol[j]);
cout << (answer == oo ? -1 : answer) << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(0);
int t = 1;
//cin >> t;
while(t--) process();
}
Compilation message
construction.cpp: In function 'void process()':
construction.cpp:61:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i = 1; i < temp.size(); i++){
| ~~^~~~~~~~~~~~~
construction.cpp:80:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int i = 1; i < temp.size(); i++){
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |