답안 #1001216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001216 2024-06-18T17:04:14 Z andrei_iorgulescu 시간이 돈 (balkan11_timeismoney) C++14
95 / 100
1002 ms 1120 KB
#include <bits/stdc++.h>

using namespace std;

struct edge
{
    int x,y,t,c;
};

int n,m;
edge a[10005];
vector<pair<int,pair<int,int>>> e;
int idx[300][300];

struct sol
{
    vector<bool> use;
    int v,sumtime,summoney;
};

sol ans;

int tt[205],sz[205];

int rep(int x)
{
    while (x != tt[x])
        x = tt[x];
    return x;
}

void join(int x,int y)
{
    x = rep(x);
    y = rep(y);
    if (x == y)
        return;
    if (sz[x] < sz[y])
        swap(x,y);
    sz[x] += sz[y];
    tt[y] = x;
}

signed main()
{
    ans.v = ans.sumtime = 1e9;
    ans.summoney = 1;
    cin >> n >> m;
    ans.use.resize(m + 1);
    for (int i = 1; i <= m; i++)
    {
        cin >> a[i].x >> a[i].y >> a[i].t >> a[i].c;
        idx[a[i].x][a[i].y] = i;
    }
    for (int r1 = 1; r1 <= 20; r1++)
    {
        for (int r2 = 1; r2 <= 20; r2++)
        {
            e.clear();
            for (int i = 1; i <= m; i++)
            {
                int x = a[i].x,y = a[i].y;
                int cost = a[i].c * r1 + a[i].t * r2;
                e.push_back({cost,{x,y}});
            }
            sort(e.begin(),e.end());
            for (int i = 0; i < n; i++)
                tt[i] = i,sz[i] = 1;
            vector<pair<int,int>> luate;
            for (auto it : e)
            {
                if (rep(it.second.first) != rep(it.second.second))
                {
                    luate.push_back(it.second);
                    join(it.second.first,it.second.second);
                }
            }
            sol cur;
            cur.use.resize(m + 1);
            cur.summoney = cur.sumtime = 0;
            for (auto it : luate)
            {
                int cn = idx[it.first][it.second];
                cur.use[cn] = true;
                cur.sumtime += a[cn].t;
                cur.summoney += a[cn].c;
            }
            cur.v = cur.sumtime * cur.summoney;
            if (cur.v < ans.v)
                ans = cur;
        }
    }
    for (int r1 = 1; r1 <= 256; r1 += 10)
    {
        for (int r2 = 1; r2 <= 256; r2 += 10)
        {
            e.clear();
            for (int i = 1; i <= m; i++)
            {
                int x = a[i].x,y = a[i].y;
                int cost = a[i].c * r1 + a[i].t * r2;
                e.push_back({cost,{x,y}});
            }
            sort(e.begin(),e.end());
            for (int i = 0; i < n; i++)
                tt[i] = i,sz[i] = 1;
            vector<pair<int,int>> luate;
            for (auto it : e)
            {
                if (rep(it.second.first) != rep(it.second.second))
                {
                    luate.push_back(it.second);
                    join(it.second.first,it.second.second);
                }
            }
            sol cur;
            cur.use.resize(m + 1);
            cur.summoney = cur.sumtime = 0;
            for (auto it : luate)
            {
                int cn = idx[it.first][it.second];
                cur.use[cn] = true;
                cur.sumtime += a[cn].t;
                cur.summoney += a[cn].c;
            }
            cur.v = cur.sumtime * cur.summoney;
            if (cur.v < ans.v)
                ans = cur;
        }
    }
    cout << ans.sumtime << ' ' << ans.summoney << '\n';
    for (int i = 1; i <= m; i++)
        if (ans.use[i])
            cout << a[i].x << ' ' << a[i].y << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 13 ms 596 KB Output is correct
6 Correct 11 ms 604 KB Output is correct
7 Correct 65 ms 784 KB Output is correct
8 Correct 1002 ms 1116 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 26 ms 568 KB Output is correct
15 Correct 20 ms 604 KB Output is correct
16 Correct 174 ms 764 KB Output is correct
17 Correct 154 ms 764 KB Output is correct
18 Correct 154 ms 600 KB Output is correct
19 Correct 876 ms 1120 KB Output is correct
20 Incorrect 887 ms 1116 KB Output isn't correct