# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
660807 | 600Mihnea | 시간이 돈 (balkan11_timeismoney) | C++17 | 436 ms | 604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
bool home = 0;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Edge
{
int a;
int b;
int x;
int y;
};
ll coef;
ll total;
bool operator < (Edge first, Edge second)
{
return coef * first.x + (total - coef) * first.y < coef * second.x + (total - coef) * second.y;
}
int n;
int m;
vector<Edge> edges;
vector<int> t;
vector<int> P;
vector<int> S;
void clr()
{
t.resize(n);
iota(t.begin(), t.end(), 0);
}
int root(int a)
{
if (t[a] == a)
{
return a;
}
else
{
return t[a] = root(t[a]);
}
}
void join(int a, int b)
{
t[root(a)] = root(b);
}
ll get(ll c)
{
P.clear();
coef = c;
sort(edges.begin(), edges.end());
clr();
int X = 0, Y = 0;
vector<pair<int, int>> T;
for (auto &it : edges)
{
if (root(it.a) != root(it.b))
{
join(it.a, it.b);
X += it.x;
Y += it.y;
T.push_back({it.a, it.b});
}
}
P.push_back(X);
P.push_back(Y);
for (auto &IT : T)
{
P.push_back(IT.first);
P.push_back(IT.second);
}
return 1LL * X * Y;
}
int main()
{
if (home == 0)
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
else
{
freopen ("input.txt", "r", stdin);
}
cin >> n >> m;
edges.resize(m);
for (auto &it : edges)
{
cin >> it.a >> it.b >> it.x >> it.y;
}
total = (ll) 1e9;
ll sol = (ll) 1e18;
for (ll c = 0; c <= total; c += (ll) 1e6)
{
ll cur = get(c);
if (cur < sol)
{
sol = cur;
S = P;
}
}
///cout << sol << "\n";
for (int i = 0; i < (int) S.size(); i++)
{
cout << S[i] << " ";
if (i % 2 == 1)
{
cout << "\n";
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |