QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#342384 | #4087. 철도 | duongnc000 | 0 | 0ms | 0kb | C++20 | 2.9kb | 2024-03-01 11:01:26 | 2024-03-01 11:01:27 |
answer
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;
const int mxN = 200 + 5;
const int mod = 1e9 + 7;
const i64 oo = 1e18;
queue<int> q;
bool vis[mxN];
int sz[mxN], dis[mxN], tot_sz;
vector<int> G[mxN], cdis[mxN];
void get_sz(int v, int p) {
sz[v] = 1;
for (int u : G[v]) {
if (vis[u] || u == p) continue;
get_sz(u, v); sz[v] += sz[u];
}
}
int find_cen(int v, int p) {
for (int u : G[v]) {
if (u == p || vis[u]) continue;
if (sz[u] > (tot_sz >> 1)) return find_cen(u, v);
}
return v;
}
vector< pair<int, int> > encode_map(int N, int K, int &X, vector< pair<int, int> > E) {
for (auto [u, v] : E) {
G[u].emplace_back(v);
G[v].emplace_back(u);
}
get_sz(1, 0);
tot_sz = find_cen(1, 0);
X = find_cen(1, 0);
memset(dis, -1, sizeof dis);
q.emplace(X); dis[X] = 0;
while (not q.empty()) {
int v = q.front(); q.pop();
cdis[dis[v]].emplace_back(v);
for (int u : G[v]) if (dis[u] == -1) {
dis[u] = dis[v] + 1;
q.emplace(u);
}
}
vector<pair<int, int>> res;
for (int i = 1; i <= N; ++i) {
int sz = isz(cdis[i]);
for (int j = 0; j < sz; ++j) for (int k = j + 1; k < sz; ++k) {
if (K) {
--K;
res.emplace_back(cdis[i][j], cdis[i][k]);
}
}
}
assert(K == 0);
return res;
}
vector< pair<int, int> > decode_map(int N, int K, int X, vector< pair<int, int> > E) {
map<pair<int, int>, int> mp;
for (auto [u, v] : E) {
G[u].emplace_back(v);
G[v].emplace_back(u);
mp[{u, v}]++;
}
memset(dis, -1, sizeof dis);
q.emplace(X); dis[X] = 0;
while (not q.empty()) {
int v = q.front(); q.pop();
cdis[dis[v]].emplace_back(v);
for (int u : G[v]) if (dis[u] != -1) {
dis[u] = dis[v] + 1;
q.emplace(u);
}
}
for (int i = 1; i <= N; ++i) {
int sz = isz(cdis[i]);
for (int j = 0; j < sz; ++j) for (int k = j + 1; k < sz; ++k) {
if (mp.count({cdis[i][j], cdis[i][k]})) mp.erase({cdis[i][j], cdis[i][k]});
if (mp.count({cdis[i][k], cdis[i][j]})) mp.erase({cdis[i][k], cdis[i][j]});
}
}
vector<pair<int, int>> res;
for (auto [tmp, _] : mp) res.push_back(tmp);
return res;
}
// int main() {
// int X;
// auto res = encode_map(6, 2, X, {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}});
// cout << X << endl;
// for (auto [u, v] : res) cout << u << ", " << v << endl;
// }
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Stage 1: Program answer Memory Limit Exceeded
Test #1:
score: 0
Stage 1: Program answer Memory Limit Exceeded
input:
jlsvaji35cwcxva-INPUT-gwl9ravworar2t1 200 4 1 2 3 3 1 4 1 4 1 1 4 3 1 2 1 4 1 4 3 1 3 2 1 3 1 2 1 3 1 4 1 1 4 4 3 2 3 4 1 3 1 1 4 2 1 3 1 1 3 2 1 4 1 2 4 1 2 3 4 4 1 2 3 1 3 4 1 4 1 3 1 1 4 2 3 4 1 3 2 1 4 4 2 3 1 3 1 2 3 4 1 2 4 1 4 4 3 3 1 3 1 2 1 3 1 1 3 2 3 4 1 2 4 4 1 3 1 4 1 2 4 1 4 3 1 3 1 2 ...
output:
input:
output:
result:
Subtask #2:
score: 0
Skipped
Subtask #3:
score: 0
Stage 1: Program answer Runtime Error
Test #37:
score: 0
Stage 1: Program answer Runtime Error
input:
jlsvaji35cwcxva-INPUT-gwl9ravworar2t1 196 24 11 13 17 4 8 22 19 15 13 10 14 6 10 9 6 23 1 1 15 5 9 12 23 16 21 8 5 11 24 2 22 21 11 18 3 3 20 20 12 17 7 19 18 24 2 14 16 22 10 16 11 3 15 6 5 17 19 15 17 11 18 20 10 8 1 14 22 4 3 22 8 2 21 12 14 1 9 19 12 7 4 10 13 18 7 21 16 5 2 13 6 42 6 11 24 14 3...
output:
input:
output:
result:
Subtask #4:
score: 0
Stage 1: Program answer Memory Limit Exceeded
Test #72:
score: 0
Stage 1: Program answer Memory Limit Exceeded
input:
jlsvaji35cwcxva-INPUT-gwl9ravworar2t1 196 146 27 27 45 119 45 4 45 61 45 1 45 115 45 51 45 16 45 134 45 83 45 64 45 86 45 7 45 62 45 78 45 46 17 128 45 30 17 41 45 14 45 12 45 52 45 32 45 139 45 96 45 84 45 116 17 11 45 72 131 42 45 105 45 106 45 130 45 125 45 127 45 112 45 22 45 100 17 70 17 43 45 ...
output:
input:
output:
result:
Subtask #5:
score: 0
Skipped