답안 #1001192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001192 2024-06-18T16:52:13 Z andrei_iorgulescu 시간이 돈 (balkan11_timeismoney) C++14
70 / 100
415 ms 2652 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;
map<pair<int,int>,int> timp, cost, idx;
 
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;
}
 
int 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;
        timp[{a[i].x,a[i].y}] = a[i].t;
        cost[{a[i].x,a[i].y}] = a[i].c;
        idx[{a[i].x,a[i].y}] = i;
    }
    for (int rata = 1; rata <= 200; rata++)
    {
        e.clear();
        for (int i = 1; i <= m; i++)
        {
            int x = a[i].x,y = a[i].y;
            int cost = a[i].c + rata * a[i].t;
            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)
        {
            cur.use[idx[it]] = true;
            cur.sumtime += timp[it];
            cur.summoney += cost[it];
        }
        cur.v = cur.sumtime * cur.summoney;
        if (cur.v < ans.v)
            ans = cur;
    }
    for (int rata = 1; rata <= 200; rata++)
    {
        e.clear();
        for (int i = 1; i <= m; i++)
        {
            int x = a[i].x,y = a[i].y;
            int cost = a[i].c * rata + a[i].t;
            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)
        {
            cur.use[idx[it]] = true;
            cur.sumtime += timp[it];
            cur.summoney += cost[it];
        }
        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 10 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 7 ms 348 KB Output is correct
6 Correct 10 ms 348 KB Output is correct
7 Correct 55 ms 860 KB Output is correct
8 Correct 415 ms 2648 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Incorrect 3 ms 344 KB Output isn't correct
13 Correct 2 ms 464 KB Output is correct
14 Correct 8 ms 348 KB Output is correct
15 Incorrect 9 ms 344 KB Output isn't correct
16 Incorrect 63 ms 860 KB Output isn't correct
17 Incorrect 62 ms 856 KB Output isn't correct
18 Correct 78 ms 860 KB Output is correct
19 Incorrect 384 ms 2652 KB Output isn't correct
20 Incorrect 362 ms 2652 KB Output isn't correct