답안 #741427

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741427 2023-05-14T05:07:11 Z abcvuitunggio 시간이 돈 (balkan11_timeismoney) C++17
45 / 100
4 ms 724 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct edge{
    int u,v,t,c;
}e[10001];
int n,m,p[201],sz[201],mx,rest,last;
vector <int> v;
int f(int i){
    return (p[i]==i?i:p[i]=f(p[i]));
}
int unite(int i, int j){
    i=f(i);
    j=f(j);
    if (i==j)
        return 0;
    if (sz[i]<sz[j])
        swap(i,j);
    p[j]=i;
    sz[i]+=sz[j];
    return 1;
}
pair <int, int> calc(int x){
    int time=0,cost=0;
    for (int i=0;i<n;i++){
        p[i]=i;
        sz[i]=1;
    }
    v.clear();
    for (int i=1;i<=m;i++){
        if (time+e[i].t>x)
            continue;
        int y=unite(e[i].u,e[i].v);
        time+=y*e[i].t;
        cost+=y*e[i].c;
        if (y)
            v.push_back(i);
    }
    return {time,cost};
}
int32_t main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n >> m;
    for (int i=1;i<=m;i++){
        cin >> e[i].u >> e[i].v >> e[i].t >> e[i].c;
        last+=e[i].t;
    }
    sort(e+1,e+m+1,[](edge a, edge b){return a.t*a.c<b.t*b.c;});
    while (true){
        auto [t,c]=calc(last);
        if (v.size()<n-1)
            break;
        if (t*c>mx){
            mx=t*c;
            rest=last;
        }
        last=t-1;
    }
    auto [t,c]=calc(rest);
    cout << t << ' ' << c << '\n';
    for (int i:v)
        cout << e[i].u << ' ' << e[i].v << '\n';
}

Compilation message

timeismoney.cpp: In function 'int32_t main()':
timeismoney.cpp:51:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   51 |         if (v.size()<n-1)
      |             ~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 724 KB Output is correct
9 Correct 0 ms 328 KB Output is correct
10 Incorrect 1 ms 212 KB Output isn't correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Incorrect 1 ms 212 KB Output isn't correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Incorrect 1 ms 344 KB Output isn't correct
19 Incorrect 4 ms 724 KB Output isn't correct
20 Incorrect 4 ms 724 KB Output isn't correct