#include "citymapping.h"
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
// #define int long long
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template<typename T, typename U>
ostream & operator << (ostream &out, const pair<T, U> &c) {
out << c.first << ' ' << c.second;
return out;
}
template<typename T>
ostream & operator << (ostream &out, vector<T> &v) {
const int sz = v.size();
for (int i = 0; i < sz; i++) {
if (i) out << ' ';
out << v[i];
}
return out;
}
template<typename T>
istream & operator >> (istream &in, vector<T> &v) {
for (T &x : v) in >> x;
return in;
}
template<typename T>
void mxx(T &a, T b){if(b > a) a = b;}
template<typename T>
void mnn(T &a, T b){if(b < a) a = b;}
void find_roads(int n, int Q, int A[], int B[], int W[]) {
queue<pair<int, vector<int>>> q;
vector<ll> dis(n + 1, 0);
vector<int> tmp;
auto get = [&](int x, int y) -> ll {
return get_distance(x, y);
};
for(int i = 2; i <= n; i++) {
dis[i] = get(1, i);
tmp.pb(i);
}
q.push({1, tmp});
int cnt = 0;
auto add = [&](int a, int b, int w) -> void {
A[cnt] = a;
B[cnt] = b;
W[cnt++] = w;
};
while(q.size()) {
int x = q.front().ff;
tmp = q.front().ss;
q.pop();
sort(all(tmp), [&](int xx, int yy) -> bool {
return dis[xx] < dis[yy];
});
vector<pair<int, vector<int>>> c;
for(int y : tmp) {
if(c.size() == 0) {c.pb({y, vector<int>()}); add(x, y, dis[y] - dis[x]);}
else {
bool did = 0;
for(auto &it : c) {
if(dis[y] + dis[it.ff] - dis[x] * 2 - (dis[it.ff] - dis[x]) * 2 == dis[y] - dis[it.ff]) {
// add(it.ff, y, dis[y] - dis[it.ff]);
it.ss.pb(y);
did = 1;
break;
}
}
if(!did) {
int mn = dis[y] - dis[x];
int par = x;
int cnt = 0, id = -1;
for(auto &it : c) {
int val = get(y, it.ff);
if(val < mn) {
mn = val;
par = it.ff;
id = cnt;
}
cnt++;
}
if(par == x) {
add(x, y, mn);
c.pb({y, vector<int>()});
} else {
c[id].ss.pb(y);
}
}
}
}
while(c.size()) {
q.push(c.back());
c.pop_back();
}
}
// assert(cnt == n - 1);
return;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
488 KB |
Reported list of edges differ from actual. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
488 KB |
Reported list of edges differ from actual. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
468 KB |
Reported list of edges differ from actual. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
468 KB |
Reported list of edges differ from actual. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
488 KB |
Reported list of edges differ from actual. |
2 |
Halted |
0 ms |
0 KB |
- |