답안 #1029257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029257 2024-07-20T14:19:08 Z lucri 시간이 돈 (balkan11_timeismoney) C++17
100 / 100
1061 ms 1368 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]);
}
long long x,xx,y,yy;
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';
        }
    }
}
long long det(long long x,long long y,long long xx,long long yy,long long xxx,long long yyy)
{
    return x*yy+xx*yyy+xxx*y-xx*y-xxx*yy-x*yyy;
}
void imbunatatire(int x,int y,int xx,int yy)
{
    calculeaza(abs(yy-y),abs(xx-x));
    if(sumt*summ<vmax)
    {
        st=sumt,sm=summ;
        vmax=sumt*summ;
        p1=abs(yy-y);
        p2=abs(xx-x);
    }
    if(det(x,y,xx,yy,sumt,summ)==0)
        return;
    long long c1=sumt,c2=summ;
    imbunatatire(x,y,c1,c2);
    imbunatatire(xx,yy,c1,c2);
}
int main()
{
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
    cin>>n>>m;
    for(long long i=1;i<=m;++i)
        cin>>u[i]>>v[i]>>ti[i]>>mo[i];
    calculeaza(1,0);
    if(sumt*summ<vmax)
    {
        st=sumt,sm=summ;
        vmax=sumt*summ;
        p1=1;
        p2=0;
    }
    x=sumt;
    y=summ;
    calculeaza(0,1);
    if(sumt*summ<vmax)
    {
        st=sumt,sm=summ;
        vmax=sumt*summ;
        p1=0;
        p2=1;
    }
    xx=sumt;
    yy=summ;
    imbunatatire(x,y,xx,yy);
    cout<<st<<' '<<sm<<'\n';
    scrie(p1,p2);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 7 ms 1116 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 7 ms 512 KB Output is correct
15 Correct 4 ms 348 KB Output is correct
16 Correct 123 ms 604 KB Output is correct
17 Correct 125 ms 600 KB Output is correct
18 Correct 137 ms 600 KB Output is correct
19 Correct 1022 ms 1368 KB Output is correct
20 Correct 1061 ms 1164 KB Output is correct