답안 #580736

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580736 2022-06-21T17:47:18 Z Lobo 시간이 돈 (balkan11_timeismoney) C++17
60 / 100
2000 ms 1196 KB
#include<bits/stdc++.h>
using namespace std;

const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
// #define int long long
#define dbl double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

const int maxn = 220;

int n, m, mark[maxn];
pair<dbl,int> d[maxn];
vector<int> g[maxn];
pair<int,pair<int,int>> ans;
vector<pair<pair<int,int>,pair<int,int>>> edg;
vector<pair<int,int>> ansv;

pair<int,int> mst(dbl c1, dbl t1) {
    // priority_queue<pair<dbl,int>, vector<pair<dbl,int>>, greater<pair<dbl,int>>> pq;
    
    for(int i = 1; i <= n; i++) {
        d[i] = mp(inf1,0);
        mark[i] = 0;
    }

    mark[1] = 1;
    for(auto id : g[1]) {
        int v = edg[id].fr.fr^edg[id].fr.sc^1;
        int c = edg[id].sc.fr;
        int t = edg[id].sc.sc;
        d[v] = min(d[v],mp(c*c1+t*t1,id));
    }

    int C = 0;
    int T = 0;
    vector<pair<int,int>> curv;
    while((int) curv.size() != n-1) {
        pair<dbl,int> cur = mp(inf1,0);
        for(int i = 1; i <= n; i++) {
            if(mark[i]) continue;
            cur = min(cur,d[i]);
        }

        int id = cur.sc;
        int u = edg[id].fr.fr;
        int v = edg[id].fr.sc;
        int v1;
        if(mark[u]) v1 = v;
        else v1 = u;
        int c = edg[id].sc.fr;
        int t = edg[id].sc.sc;

        curv.pb(mp(edg[id].fr.fr,edg[id].fr.sc));
        C+= c;
        T+= t;

        mark[v1] = 1;
        for(auto id1 : g[v1]) {
            int v2 = edg[id1].fr.fr^edg[id1].fr.sc^v1;
            int c2 = edg[id1].sc.fr;
            int t2 = edg[id1].sc.sc;
            d[v2] = min(d[v2],mp(c2*c1+t2*t1,id1));
        }
    }

    if(ans.fr > C*T) {
        ans.fr = C*T;
        ans.sc = mp(C,T);
        swap(ansv,curv);
    }
    // cout << " " << c1 << " " << t1 << " " << C << " " << T << endl;
    return mp(C,T);
}

void dec(int cl, int tl, int cr, int tr) {
    // cout << cl << " " << tl << " " << cr << " " << tr << endl;
    int dc = cr-cl; // > 0
    int dt = tr-tl; // < 0
    dbl sz = sqrt(dc*dc + dt*dt);
    auto aux = mst(dt/sz,-dc/sz);
    int c = aux.fr;
    int t = aux.sc;
    if(c == cl || c == cr) return;
    dec(cl,tl,c,t);
    dec(c,t,cr,tr);
}

void solve() {
    cin >> n >> m;

    for(int i = 0; i < m; i++) {
        int u,v,c,t; cin >> u >> v >> c >> t;
        u++;
        v++;
        edg.pb(mp(mp(u,v),mp(c,t)));
        g[u].pb(i);
        g[v].pb(i);
    }

    ans.fr = inf1;
    pair<int,int> aux;
    aux = mst(0,1);
    int c0 = aux.fr;
    int t0 = aux.sc;
    aux = mst(1,0);
    int c1 = aux.fr;
    int t1 = aux.sc;
    dec(c0,t0,c1,t1);

    cout << ans.sc.fr << " " << ans.sc.sc << endl;
    for(auto x : ansv) {
        cout << x.fr-1 << " " << x.sc-1 << endl;
    }
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Incorrect 3 ms 340 KB Output isn't correct
8 Correct 8 ms 724 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 8 ms 340 KB Output is correct
15 Correct 18 ms 340 KB Output is correct
16 Execution timed out 2076 ms 1180 KB Time limit exceeded
17 Execution timed out 2076 ms 1164 KB Time limit exceeded
18 Execution timed out 2076 ms 1196 KB Time limit exceeded
19 Execution timed out 2047 ms 1156 KB Time limit exceeded
20 Execution timed out 2069 ms 1180 KB Time limit exceeded