253592026-02-19 13:49:05Leventusz09Társasjátékcpp17Runtime error 0/100563ms262144 KiB
#include <iostream>
#include <limits.h>
#include <vector>
#define int long long

using namespace std;

struct Edge {
    int to;
    int cost;
};

struct Node {
    bool ty = 0;
    bool szomoru;
    int c = -1, oc = -1;
    vector<Edge> et;
} G[100'000];

void cszs(const int&index){
    if(G[index].ty) return;
    G[index].szomoru = 1;
    for(const Edge&e:G[index].et){
        cszs(e.to);
        if(G[e.to].szomoru) G[index].szomoru = 0;
    }

    G[index].ty = 1;
}

void con(const int& index){
    if(G[index].c >= 0) return;
    if(G[index].et.size() == 0){
        G[index].c = 0;
        G[index].oc = 0;
        return;
    }
    if(G[index].szomoru){
        Edge *mt = &G[index].et[1];
        con(mt->to);
        int mc = G[mt->to].c;
        for(Edge& e: G[index].et){
            con(e.to);
            if(G[e.to].c > mc){
                mt = &e;
                mc = G[e.to].c;
            }
        }
        G[index].c = G[mt->to].oc + mt->cost;
        G[index].oc = mc;
        return;
    }
    int mc = LLONG_MAX;
    Edge *mt = &G[index].et[0];
    for(Edge& e: G[index].et){
        if(!G[e.to].szomoru) continue;
        con(e.to);
        if(G[e.to].oc < mc){
            mt = &e;
            mc = G[e.to].oc;
        }
    }
    G[index].c = mc + mt->cost;
    G[index].oc = G[mt->to].c;
}

signed main(){
    int N, M;
    cin >> N >> M;

    for(int i=0; i<M; i++){
        int U, V, W;
        cin >> U >> V >> W;
        U--; V--;
        Edge e;
        e.to = V;
        e.cost = W;
        G[U].et.push_back(e);
    }

    cszs(0);
    con(0);
    if(G[0].szomoru) cout << "Bob" << endl << G[0].oc << endl;
    else cout << "Alice" << endl << G[0].c << endl;

    /*for(int i=0; i<N; i++){
        cout << i +1<< ": " << G[i].szomoru << "\t" << G[i].c << " " << G[i].oc << endl;
    }*/
   return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted4ms4916 KiB
2Runtime error542ms262144 KiB
subtask20/10
3Accepted4ms5108 KiB
4Runtime error236ms262144 KiB
5Runtime error282ms262144 KiB
6Runtime error280ms262144 KiB
7Runtime error231ms262144 KiB
subtask30/15
8Runtime error238ms262144 KiB
9Runtime error237ms262144 KiB
10Runtime error386ms262144 KiB
11Runtime error407ms262144 KiB
12Runtime error328ms262144 KiB
13Runtime error444ms262144 KiB
14Runtime error437ms262144 KiB
15Runtime error513ms262144 KiB
16Runtime error505ms262144 KiB
17Runtime error433ms262144 KiB
18Runtime error365ms262144 KiB
19Runtime error497ms262144 KiB
subtask40/40
20Runtime error236ms262144 KiB
21Runtime error282ms262144 KiB
22Runtime error397ms262144 KiB
23Runtime error465ms262144 KiB
24Runtime error442ms262144 KiB
25Runtime error493ms262144 KiB
26Accepted231ms10036 KiB
27Runtime error365ms262144 KiB
28Runtime error490ms262144 KiB
subtask50/35
29Accepted6ms4916 KiB
30Runtime error501ms262144 KiB
31Accepted4ms5108 KiB
32Runtime error236ms262144 KiB
33Runtime error282ms262144 KiB
34Runtime error280ms262144 KiB
35Runtime error231ms262144 KiB
36Runtime error238ms262144 KiB
37Runtime error237ms262144 KiB
38Runtime error386ms262144 KiB
39Runtime error407ms262144 KiB
40Runtime error328ms262144 KiB
41Runtime error444ms262144 KiB
42Runtime error437ms262144 KiB
43Runtime error513ms262144 KiB
44Runtime error505ms262144 KiB
45Runtime error433ms262144 KiB
46Runtime error365ms262144 KiB
47Runtime error497ms262144 KiB
48Runtime error236ms262144 KiB
49Runtime error282ms262144 KiB
50Runtime error397ms262144 KiB
51Runtime error465ms262144 KiB
52Runtime error442ms262144 KiB
53Runtime error493ms262144 KiB
54Accepted231ms10036 KiB
55Runtime error365ms262144 KiB
56Runtime error490ms262144 KiB
57Runtime error282ms262144 KiB
58Runtime error248ms262144 KiB
59Runtime error293ms262144 KiB
60Runtime error500ms262144 KiB
61Runtime error560ms262144 KiB
62Runtime error563ms262144 KiB
63Runtime error501ms262144 KiB
64Runtime error423ms262144 KiB