답안 #1010119

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010119 2024-06-28T10:40:57 Z vjudge1 시간이 돈 (balkan11_timeismoney) C++17
0 / 100
2000 ms 65536 KB
// ^^
// <{:3
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,tune=native")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
//#define int long signed long int
#define ld long double
using namespace std;
const int maxn = 202;
vector<tuple<ld, ld, int, int>> edges; // c t x y
pair<int, ld> ans; // val, k
int p[maxn];
int n, m;

inline void rt() { for(int i = 0; i <= n; ++i) p[i] = i; }

int f(int x)
{
    if(p[x] == x) return x;
    return p[x] = f(p[x]);
}

inline void u(int x, int y)
{
    x = f(x); y = f(y);
    if(x == y) return;
    p[x] = y;
}

pair<int, int> mst(ld k)
{
    vector<tuple<ld, ld, ld, int, int>> v;
    rt();

    for(auto [c, t, x, y] : edges) v.emplace_back(t+k*c, c, t, x, y);
    sort(v.begin(), v.end());

    pair<int, int> ret(0, 0);
    for(auto [val, c, t, x, y] : v)
    {
        if(f(x) != f(y))
        {
            ret.first += c;
            ret.second += t;
            u(x, y);
        }
    }

    return ret;
}

void rec(ld x1, ld y1, ld x2, ld y2)
{
    ld k = (y1 - y2) / (x1 - x2);
    ld c = y1 - (k * x1);

    pair<int, int> novi = mst(-k);

    ld y = (k*novi.first) + c;

    //cout << novi.first << " " << novi.second << " " << k << " dbdb\n";

    if(novi.second >= y) return;

    if(novi.first * novi.second < ans.first)
    {
        ans.first = novi.first * novi.second;
        ans.second = k;
    }

    rec(x1, y1, novi.first, novi.second);
    rec(novi.first, novi.second, x1, y1);
}

signed main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    ans = {1e9, 0};

    cin >> n >> m;

    for(int i = 0; i < m; ++i)
    {
        ld t, c;
        int x, y;
        cin >> x >> y >> t >> c;
        edges.emplace_back(t, c, x, y);
    }

    rt();
    sort(edges.begin(), edges.end());
    pair<int, int> mint(0, 0);
    for(auto &[t, c, x, y] : edges)
    {
        int xtr = f(x), ytr = f(y);
        if(xtr != ytr)
        {
            mint.first += c;
            mint.second += t;
            u(xtr, ytr);
        }
        swap(t, c);
    }

    rt();
    sort(edges.begin(), edges.end());
    pair<int, int> minc(0, 0);
    for(auto &[c, t, x, y] : edges)
    {
        int xtr = f(x), ytr = f(y);
        if(xtr != ytr)
        {
            minc.first += c;
            minc.second += t;
            u(xtr, ytr);
        }
    }

    rec(minc.first, minc.second, mint.first, mint.second);

    //cout << ans.first << " " << ans.second;


    rt();
    ld k = -ans.second;
    vector<tuple<ld, ld, ld, int, int>> v;
    for(auto [c, t, x, y] : edges) v.emplace_back(t+k*c, c, t, x, y);

    sort(v.begin(), v.end());

    pair<int, int> ret(0, 0);
    vector<pair<int, int>> ansedge;
    for(auto [val, c, t, x, y] : v)
    {
        if(f(x) != f(y))
        {
            ret.first += c;
            ret.second += t;
            u(x, y);
            ansedge.emplace_back(x, y);
        }
    }

    swap(ret.first, ret.second);
    cout << ret.first << " " << ret.second << "\n";
    for(auto [x, y] : ansedge) cout << x << " " << y << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2055 ms 5980 KB Time limit exceeded
2 Runtime error 1922 ms 65536 KB Execution killed with signal 9
3 Execution timed out 2029 ms 54172 KB Time limit exceeded
4 Execution timed out 2098 ms 17980 KB Time limit exceeded
5 Execution timed out 2067 ms 3412 KB Time limit exceeded
6 Execution timed out 2035 ms 3724 KB Time limit exceeded
7 Execution timed out 2057 ms 1300 KB Time limit exceeded
8 Execution timed out 2073 ms 2860 KB Time limit exceeded
9 Incorrect 0 ms 348 KB Output isn't correct
10 Execution timed out 2100 ms 31204 KB Time limit exceeded
11 Incorrect 1 ms 348 KB Output isn't correct
12 Execution timed out 2096 ms 17912 KB Time limit exceeded
13 Execution timed out 2070 ms 16052 KB Time limit exceeded
14 Execution timed out 2087 ms 3676 KB Time limit exceeded
15 Execution timed out 2029 ms 3960 KB Time limit exceeded
16 Execution timed out 2037 ms 1344 KB Time limit exceeded
17 Execution timed out 2051 ms 1388 KB Time limit exceeded
18 Execution timed out 2041 ms 1412 KB Time limit exceeded
19 Execution timed out 2093 ms 2836 KB Time limit exceeded
20 Execution timed out 2052 ms 2692 KB Time limit exceeded