답안 #113955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113955 2019-05-29T09:48:20 Z Kastanda 시간이 돈 (balkan11_timeismoney) C++11
90 / 100
2000 ms 632 KB
#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;
    for (int i = 0; i < 300; i++)
    {
        rt = i; rc = 300; MST();
        rc = i; rt = 300; MST();
    }
    for (int i = 0; i < 800; i++)
    {
        rt = i; rc = 3; MST();
        rc = i; rt = 3; 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;
}

Compilation message

timeismoney.cpp: In function 'int main()':
timeismoney.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
timeismoney.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d", &a, &b, &c, &d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 256 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
5 Correct 38 ms 384 KB Output is correct
6 Correct 32 ms 384 KB Output is correct
7 Correct 198 ms 384 KB Output is correct
8 Correct 959 ms 632 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 8 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 10 ms 256 KB Output is correct
13 Correct 10 ms 128 KB Output is correct
14 Correct 71 ms 376 KB Output is correct
15 Correct 56 ms 376 KB Output is correct
16 Correct 409 ms 444 KB Output is correct
17 Correct 411 ms 504 KB Output is correct
18 Correct 408 ms 504 KB Output is correct
19 Execution timed out 2051 ms 512 KB Time limit exceeded
20 Execution timed out 2056 ms 512 KB Time limit exceeded