# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
476985 | Jasiekstrz | 시간이 돈 (balkan11_timeismoney) | C++17 | 2091 ms | 62916 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=200;
const int C=255;
const int M=1e4;
struct Edge
{
int a,b;
int c1,c2;
};
Edge edg[M+10];
int fau[N+10];
int ans1=N*C+7,ans2=N*C+7;
vector<pair<int,int>> ans;
void clr_fau(int n)
{
for(int i=0;i<=n;i++)
fau[i]=i;
return;
}
int f(int x)
{
return (fau[x]==x ? x:fau[x]=f(fau[x]));
}
void u(int x,int y)
{
fau[f(x)]=f(y);
return;
}
pair<int,int> mst(int n,int m,int k1,int k2)
{
int w1=0,w2=0;
vector<pair<int,int>> in_mst;
clr_fau(n);
sort(edg+1,edg+m+1,[k1,k2](Edge e1,Edge e2){ return e1.c1*k1+e1.c2*k2<e2.c1*k1+e2.c2*k2; });
for(int ei=1;ei<=m;ei++)
{
auto e=edg[ei];
if(f(e.a)!=f(e.b))
{
u(e.a,e.b);
w1+=e.c1;
w2+=e.c2;
in_mst.emplace_back(e.a,e.b);
}
}
if((long long)w1*w2<(long long)ans1*ans2)
{
ans1=w1;
ans2=w2;
ans=in_mst;
}
//cerr<<k1<<" "<<k2<<" -> "<<w1<<" "<<w2<<"\n";
return {w1,w2};
}
void solve(int n,int m,pair<int,int> p1,pair<int,int> p2)
{
auto p3=mst(n,m,p2.se-p1.se,p1.fi-p2.fi);
if(p3==p1 || p3==p2)
return;
solve(n,m,p1,p3);
solve(n,m,p3,p2);
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++)
cin>>edg[i].a>>edg[i].b>>edg[i].c1>>edg[i].c2;
solve(n,m,mst(n,m,0,1),mst(n,m,1,0));
cout<<ans1<<" "<<ans2<<"\n";
for(auto [a,b]:ans)
cout<<a<<" "<<b<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |