# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
113951 | Kastanda | 시간이 돈 (balkan11_timeismoney) | C++11 | 639 ms | 524 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
struct Edge {int a, b, c, t;};
const int N = 205, M = 10004;
int n, m, rc, rt, smc, smt, P[N];
Edge E[M], R[N];
int Find(int v)
{
return (P[v] < 0 ? v : (P[v] = Find(P[v])));
}
inline bool CMP(Edge e1, Edge e2)
{
return (e1.c * rc + e1.t * rt < e2.c * rc + e2.t * rt);
}
inline void MST()
{
int _smc = 0, _smt = 0;
vector < Edge > vec;
sort(E, E + m, CMP);
memset(P, -1, sizeof(P));
for (int i = 0; i < m; i++)
if (Find(E[i].a) != Find(E[i].b))
{
P[Find(E[i].a)] = Find(E[i].b);
_smc += E[i].c;
_smt += E[i].t;
vec.push_back(E[i]);
}
if (1LL * smc * smt > 1LL * _smc * _smt)
{
smc = _smc; smt = _smt;
for (int i = 0; i < n - 1; i++)
R[i] = vec[i];
}
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++)
{
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
E[i] = {a, b, c, d};
}
smc = smt = M * N; rc = 300;
for (int i = 0; i < 500; i++)
rt = i, MST();
rt = 300;
for (int i = 0; i < 500; i++)
rc = i, MST();
printf("%d %d\n", smc, smt);
for (int i = 0; i < n - 1; i++)
printf("%d %d\n", R[i].a, R[i].b);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |