QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#342403#4087. 철도duongnc000Compile Error//C++203.0kb2024-03-01 11:09:422024-03-01 11:09:44

Judging History

你现在查看的是最新测评结果

  • [2024-03-01 11:09:44]
  • 评测
  • [2024-03-01 11:09:42]
  • 提交

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) {
    memset(vis, false, sizeof vis);

    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 = 0; 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]);
            }
        }
        G[i].clear(); cdis[i].clear();
    }
    assert(K == 0);
    return res;
}

map<pair<int, int>, int> mp;

vector< pair<int, int> > decode_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);
        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]});
        }
        G[i].clear(); cdis[i].clear();
    }

    vector<pair<int, int>> res;
    for (auto [tmp, _] : mp) res.push_back(tmp);
    mp.clear();
    return res;
}

int main() {
    int X = -1;
    auto res = decode_map(4, 1, 1, {{4, 1}, {2, 3}, {3, 1}, {4, 3}});
    cout << X << endl;
    for (auto [u, v] : res) cout << u << ", " << v << endl;
}

Details

/usr/bin/ld: /tmp/ccJ6TPcd.o: in function `main':
implementer.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc9OQAye.o:answer.code:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status