제출 #1310269

#제출 시각아이디문제언어결과실행 시간메모리
1310269Tymond시간이 돈 (balkan11_timeismoney)C++20
55 / 100
21 ms1092 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

const ll INF = 1e18;
const int MAXN = 207;
const int MAXM = 1e4 + 7;
set<int> exist;
int f[MAXN];
vector<pair<pii, pii>> edges;
int n, m;
vector<pii> curr = {};
pll sum;

ll solve(int e){
    sum = mp(edges[e].se.fi, edges[e].se.se);
    curr = {edges[e].fi};
    exist.erase(e);
    for(int i = 0; i < n; i++){
        f[i] = 0;
    }
    f[edges[e].fi.fi] = f[edges[e].fi.se] = 1;

    for(int _ = 1; _ < n - 1; _++){
        int u = -1;
        pii best;
        int ind;
        for(auto j : exist){
            if(f[edges[j].fi.fi] == f[edges[j].fi.se]){
                continue;
            }

            if(f[edges[j].fi.fi] == 1){
                swap(edges[j].fi.fi, edges[j].fi.se);
            }

            if(u == -1 || ((ll)(sum.fi + best.fi) * (sum.se + best.se) >= (ll)(sum.fi + edges[j].se.fi) * (sum.se + edges[j].se.se))){
                u = edges[j].fi.fi;
                best = edges[j].se;
                ind = j;
            }
        }

        if(u == -1){
            return INF;
        }

        f[u] = 1;
        curr.pb(edges[ind].fi);
        sum.fi += best.fi;
        sum.se += best.se;
        exist.erase(ind);
    }

    return (ll)sum.fi * sum.se;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        exist.insert(i);
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        edges.pb(mp(mp(a, b), mp(c, d)));
    }

    ll best = INF;
    vector<pii> ans = {};
    pll res;
    ll mn = INF;
    int id;
    for(int i = 0; i < m; i++){
        if(edges[i].se.fi * edges[i].se.se <= mn){
            id = i;
            mn = edges[i].se.fi * edges[i].se.se;
        }
    }

    ll now = solve(id);
    best = now;
    ans = curr;
    res = sum;

    cout << res.fi << ' ' << res.se << '\n';
    for(auto ele : ans){
        cout << ele.fi << ' ' << ele.se << '\n';
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...