답안 #145864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145864 2019-08-21T08:24:04 Z TadijaSebez 시간이 돈 (balkan11_timeismoney) C++11
55 / 100
19 ms 760 KB
#include <bits/stdc++.h>
using namespace std;
#define ldb long double
#define ll long long
#define pb push_back
#define mp make_pair
struct Edge
{
	int u,v,a,b;
	Edge(){}
	Edge(int _u, int _v, int _a, int _b):u(_u),v(_v),a(_a),b(_b){}
	ldb Get(ldb k){ return k*a+(1-k)*b;}
};
vector<Edge> edges;
vector<pair<int,int>> tree;
ldb k;
bool comp(Edge x, Edge y)
{
	if(k==1) return mp(x.a,x.b)<mp(y.a,y.b);
	if(k==0) return mp(x.b,x.a)<mp(y.b,y.a);
	return x.Get(k)<y.Get(k);
}
const int N=205;
struct DSU
{
	int p[N];
	void init(){ for(int i=0;i<N;i++) p[i]=i;}
	DSU(){ init();}
	int Find(int x){ return x==p[x]?x:p[x]=Find(p[x]);}
	void Union(int x, int y){ p[Find(x)]=Find(y);}
} DS;
ll ans=9e18;
ldb ans_k;
pair<int,int> MST(ldb k)
{
	DS.init();
	tree.clear();
	::k=k;
	sort(edges.begin(),edges.end(),comp);
	int A=0,B=0;
	for(Edge e:edges)
	{
		if(DS.Find(e.u)!=DS.Find(e.v))
		{
			DS.Union(e.u,e.v);
			A+=e.a;
			B+=e.b;
			tree.pb({e.u,e.v});
		}
	}
	ans=min(ans,(ll)A*B);
	if(ans==A*B) ans_k=k;
	return {A,B};
}
bool below(pair<int,int> z, pair<int,int> x, pair<int,int> y)
{
	y.first-=x.first;
	y.second-=x.second;
	z.first-=x.first;
	z.second-=x.second;
	return z.first*y.second>z.second*y.first;
}
void Solve(pair<int,int> F, pair<int,int> S)
{
	ldb k;
	if(F.first==S.first) k=1;
	else k=(ldb)(S.first-F.first)/(S.first-F.first+F.second-S.second);
	pair<int,int> M=MST(k);
	if(below(M,F,S))
	{
		Solve(F,M);
		Solve(M,S);
	}
}
int main()
{
	int n,m,u,v,a,b;
	scanf("%i %i",&n,&m);
	for(int i=1;i<=m;i++) scanf("%i %i %i %i",&u,&v,&a,&b),u++,v++,edges.pb(Edge(u,v,a,b));
	pair<int,int> F=MST(1);
	pair<int,int> S=MST(0);
	Solve(F,S);
	pair<int,int> sol=MST(ans_k);
	printf("%i %i\n",sol.first,sol.second);
	for(auto e:tree) printf("%i %i\n",e.first-1,e.second-1);
	return 0;
}

Compilation message

timeismoney.cpp: In function 'int main()':
timeismoney.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
timeismoney.cpp:79:64: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=m;i++) scanf("%i %i %i %i",&u,&v,&a,&b),u++,v++,edges.pb(Edge(u,v,a,b));
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 9 ms 760 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Incorrect 2 ms 256 KB Output isn't correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Incorrect 3 ms 376 KB Output isn't correct
14 Incorrect 3 ms 256 KB Output isn't correct
15 Correct 3 ms 376 KB Output is correct
16 Incorrect 6 ms 376 KB Output isn't correct
17 Incorrect 5 ms 380 KB Output isn't correct
18 Incorrect 5 ms 376 KB Output isn't correct
19 Incorrect 19 ms 760 KB Output isn't correct
20 Incorrect 19 ms 732 KB Output isn't correct