// author : thembululquaUwU
// 3.9.2024
#include <bits/stdc++.h>
#include "citymapping.h"
#define pb push_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
const int N = 1e3 + 5;
const int mod = 1e9 + 7;
void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}
ll d[N][N];
ll dist(int x, int y){
if (x > y) swap(x, y);
if (x == y) return 0;
if (!d[x][y]) d[x][y] = get_distance(x, y);
return d[x][y];
}
bool del[N];
int sz[N], heavy[N];
vi adj[N];
void dfs(int u){
sz[u] = 1, heavy[u] = 0;
for (int v : adj[u]) if (!del[v]){
dfs(v); sz[u] += sz[v];
if (sz[v] > sz[heavy[u]]) heavy[u] = v;
}
}
void find_roads(int n, int q, int a[], int b[], int w[]){
vector <int> sr;
for (int i = 2; i < n + 1; ++ i) sr.pb(i);
sort(sr.begin(), sr.end(), [&](int u, int v){
return dist(1, u) < dist(1, v);
});
int nE = 0;
for (int u : sr){
int r = 1;
for (int i = 1; i <= n; ++ i) del[i] = 0;
while (true){
dfs(r); vi path = {r};
while (heavy[r]) r = heavy[r], path.pb(r);
if (path.size() == 1) break;
ll x = dist(1, path.back()) + dist(1, u) - dist(u, path.back()); x /= 2;
for (int u : path) if (dist(1, u) == x) {
r = u; break;
} else del[u] = 1;
}
adj[r].pb(u); a[nE] = r, b[nE] = u, w[nE] = dist(r, u), ++ nE;
}
}
//void solve(){
//
//}
//
//int main(){
// if (fopen("pqh.inp", "r")){
// freopen("pqh.inp", "r", stdin);
// freopen("pqh.out", "w", stdout);
// }
// ios_base::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
//
// int t = 1; // cin >> t;
// while (t --) solve();
// return 0;
//}
Compilation message
citymapping.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
19 | void maxl(auto &a, auto b) {a = max(a, b);}
| ^~~~
citymapping.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
19 | void maxl(auto &a, auto b) {a = max(a, b);}
| ^~~~
citymapping.cpp:20:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
20 | void minl(auto &a, auto b) {a = min(a, b);}
| ^~~~
citymapping.cpp:20:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
20 | void minl(auto &a, auto b) {a = min(a, b);}
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2063 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2063 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2041 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2041 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2063 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |