답안 #392554

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392554 2021-04-21T10:26:32 Z Vladth11 시간이 돈 (balkan11_timeismoney) C++14
0 / 100
774 ms 988 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;

const ll NMAX = 201;
const ll INF = (1LL << 60);
const ll MOD = 666013;
const ll BLOCK = 225;
const ll base = 31;
const ll nr_of_bits = 8;

int n;

struct edge{
    int x, y, t, c;
};

class DSU{
    vector <int> parent, cnt;
    int root(int x){
        if(x == parent[x]){
            return x;
        }
        return parent[x] = root(parent[x]);
    }
public:
    int cost, timp;
    vector <edge> fol;
    DSU(int n){
        cost = timp = 0;
        parent.resize(n + 5);
        fol.clear();
        cnt.resize(n + 5, 0);
        for(int i = 1; i <= n; i++){
            parent[i] = i;
        }
    }
    void merge(edge x){
        int a = root(x.x);
        int b = root(x.y);
        if(a == b)
            return;
        if(cnt[a] < cnt[b])
            swap(a, b);
        cnt[a] += cnt[b];
        cnt[b] = 0;
        parent[b] = a;
        cost += x.c;
        timp += x.t;
        fol.push_back(x);
    }
};

int dx, dy;
pii best;
int minim = 2e9;
int _print;

bool cmp(edge a, edge b){
    return a.t * dx + a.c * dy < b.t * dx + b.c * dy;
}

vector <edge> edges;

int OK(pii a, pii b, pii c){
    return (a.first * (b.second - c.second) + b.first * (c.second - a.second) + c.first * (a.second - b.second) == 0);
}

pii MST(){
    sort(edges.begin(), edges.end(), cmp);
    DSU dsu(n);
    for(auto x : edges){
        dsu.merge(x);
    }
    if(!_print)
        return {dsu.cost, dsu.timp};
    cout << dsu.timp << " " << dsu.cost << "\n";
    for(auto x : dsu.fol){
        cout << x.x << " " << x.y << "\n";
    }
}

void Solve(pii A, pii B){
    dx = B.first - A.first;
    dy = A.second - B.second;
    pii C = MST();
   // debug(C.first);
   // debug(C.second);
    if(OK(A, C, B)){
        return;
    }
    if(C.first * C.second < minim){
        minim = C.first * C.second;
        best = {dx, dy};
    }
    Solve(A, C);
    Solve(C, B);
}

int main() {
    //ifstream cin("grarbore.in");
    //ofstream cout("grarbore.out");
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int m;
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        edge x;
        cin >> x.x >> x.y >> x.t >> x.c;
        x.x++;
        x.y++;
        edges.push_back(x);
    }
    dx = 0;
    dy = 1;
    pii A = MST();
    dx = 1;
    dy = 0;
    pii B = MST();
    Solve(A, B);
    _print = 1;
    dx = best.first;
    dy = best.second;
    MST();
    return 0;
}

Compilation message

timeismoney.cpp: In function 'pii MST()':
timeismoney.cpp:80:14: warning: control reaches end of non-void function [-Wreturn-type]
   80 |     DSU dsu(n);
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Runtime error 3 ms 588 KB Execution killed with signal 11
3 Runtime error 3 ms 588 KB Execution killed with signal 11
4 Runtime error 3 ms 512 KB Execution killed with signal 11
5 Runtime error 1 ms 464 KB Execution killed with signal 6
6 Runtime error 1 ms 460 KB Execution killed with signal 6
7 Runtime error 3 ms 588 KB Execution killed with signal 6
8 Runtime error 10 ms 976 KB Execution killed with signal 11
9 Runtime error 3 ms 460 KB Execution killed with signal 11
10 Runtime error 3 ms 460 KB Execution killed with signal 11
11 Runtime error 3 ms 460 KB Execution killed with signal 11
12 Runtime error 3 ms 588 KB Execution killed with signal 11
13 Runtime error 3 ms 588 KB Execution killed with signal 11
14 Runtime error 7 ms 460 KB Execution killed with signal 6
15 Runtime error 5 ms 464 KB Execution killed with signal 6
16 Runtime error 102 ms 580 KB Execution killed with signal 6
17 Runtime error 92 ms 488 KB Execution killed with signal 6
18 Runtime error 89 ms 488 KB Execution killed with signal 6
19 Runtime error 757 ms 988 KB Execution killed with signal 11
20 Runtime error 774 ms 980 KB Execution killed with signal 11