Submission #1029180

# Submission time Handle Problem Language Result Execution time Memory
1029180 2024-07-20T13:33:54 Z lucri timeismoney (balkan11_timeismoney) C++17
45 / 100
2000 ms 1220 KB
#include <bits/stdc++.h>
using namespace std;
long long t[210],u[10010],v[10010],ti[10010],mo[10010],n,m,vmax=2000000000000000000,st,sm,p1,p2;
long long sumt,summ;
struct muchii{long long u,v,val,valt,valm;}a[10010];
long long tata(long long n)
{
    if(t[n]==n)return n;
    return t[n]=tata(t[n]);
}
bool comp(muchii a,muchii b)
{
    if(a.val!=b.val)return a.val<b.val;
    if(a.u!=b.u)return a.u<b.u;
    if(a.v!=b.v)return a.v<b.v;
    return a.valt<b.valt;
}
void calculeaza(long long v1,long long v2)
{
    for(long long i=0;i<n;++i)
        t[i]=i;
    for(long long i=1;i<=m;++i)
        a[i]={u[i],v[i],ti[i]*v1+mo[i]*v2,ti[i],mo[i]};
    sumt=summ=0;
    sort(a+1,a+m+1,comp);
    for(long long i=1;i<=m;++i)
    {
        if(tata(a[i].u)!=tata(a[i].v))
        {
            t[t[a[i].u]]=t[a[i].v];
            sumt+=a[i].valt;
            summ+=a[i].valm;
        }
    }
}
void scrie(long long v1,long long v2)
{
    for(long long i=0;i<n;++i)
        t[i]=i;
    for(long long i=1;i<=m;++i)
        a[i]={u[i],v[i],ti[i]*v1+mo[i]*v2,ti[i],mo[i]};
    sort(a+1,a+m+1,comp);
    for(long long i=1;i<=m;++i)
    {
        if(tata(a[i].u)!=tata(a[i].v))
        {
            t[t[a[i].u]]=t[a[i].v];
            cout<<a[i].u<<' '<<a[i].v<<'\n';
        }
    }
}
int main()
{
    cin>>n>>m;
    for(long long i=1;i<=m;++i)
        cin>>u[i]>>v[i]>>ti[i]>>mo[i];
    for(long long i=0;i<=1000;++i)
    {
        calculeaza(i,1000);
        if(sumt*summ<vmax)
        {
            st=sumt,sm=summ;
            vmax=sumt*summ;
            p1=i;
            p2=1000;
        }
        calculeaza(1000,i);
        if(sumt*summ<vmax)
        {
            st=sumt,sm=summ;
            vmax=sumt*summ;
            p1=1000;
            p2=i;
        }
    }
    cout<<st<<' '<<sm<<'\n';
    scrie(1,1);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 6 ms 444 KB Output is correct
5 Correct 38 ms 348 KB Output is correct
6 Correct 28 ms 348 KB Output is correct
7 Correct 245 ms 604 KB Output is correct
8 Execution timed out 2017 ms 1112 KB Time limit exceeded
9 Correct 1 ms 348 KB Output is correct
10 Incorrect 3 ms 348 KB Output isn't correct
11 Incorrect 3 ms 348 KB Output isn't correct
12 Incorrect 6 ms 348 KB Output isn't correct
13 Correct 6 ms 348 KB Output is correct
14 Incorrect 48 ms 472 KB Output isn't correct
15 Incorrect 34 ms 348 KB Output isn't correct
16 Incorrect 333 ms 604 KB Output isn't correct
17 Incorrect 323 ms 600 KB Output isn't correct
18 Incorrect 334 ms 596 KB Output isn't correct
19 Incorrect 1977 ms 1220 KB Output isn't correct
20 Execution timed out 2021 ms 1120 KB Time limit exceeded