Submission #1065053

# Submission time Handle Problem Language Result Execution time Memory
1065053 2024-08-18T21:49:50 Z beaconmc The Ties That Guide Us (CEOI23_incursion) C++17
30 / 100
215 ms 15128 KB
#include "incursion.h"

#include <bits/stdc++.h>
 
typedef int ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
 
using namespace std;



ll sub[50000];
vector<ll> edges[50000];
ll par[50000];
ll visited[50000];
ll depth[50000];
ll unsure[50000];
ll n;



void dfs(ll a, ll p, ll d){
    depth[a] = d;
    par[a] = p;
    sub[a] = 1;
    for (auto&i : edges[a]){
        if (i != p) dfs(i,a,d+1), sub[a] += sub[i];
    }
}

ll centfind(ll a, ll p){
    for (auto&i : edges[a]){
        if (i!=p && sub[i] > n/2) return centfind(i, a);
    }
    return a;
}





vector<int> mark(std::vector<std::pair<int, int>> F, int safe) {
    n = (ll)F.size()+1;
    vector<int> ties(n);
    FOR(i,0,50000) edges[i].clear(), sub[i] = 0, par[i] = -1, depth[i] = 0;

    for (auto&i : F){
        edges[i.first].push_back(i.second);
        edges[i.second].push_back(i.first);
    }
    dfs(1, -1, 0);

    ll cent = centfind(1, -1);

    dfs(cent, -1, 0);


    while (safe != -1){
        ties[safe-1] = 1;
        safe = par[safe];
    }

    return ties;


}

bool cmp(ll a, ll b){
    return sub[a] < sub[b];
}

void locate(std::vector<std::pair<int, int>> F, int curr, int t) {
    n = (ll)F.size()+1;

    FOR(i,0,50000) edges[i].clear(), sub[i] = 0, par[i] = -1, depth[i] = 0;

    for (auto&i : F){
        edges[i.first].push_back(i.second);
        edges[i.second].push_back(i.first);
    }
    dfs(1, -1, 0);

    ll cent = centfind(1, -1);

    dfs(cent, -1, 0);
    visited[curr] = 1;

    //cout << cent << endl;

    while (t != 1 && curr != cent){
        t = visit(par[curr]);
        curr = par[curr];
        visited[curr] = 1;
    }

    while (1){
        visited[curr] = 1;
        if (t==0 && curr!=cent){
            t = visit(par[curr]);
            curr = par[curr];
            continue;
        }
        sort(edges[curr].begin(), edges[curr].end(), cmp);
        reverse(edges[curr].begin(), edges[curr].end());
        bool done = false;
        for (auto&i : edges[curr]){
            if (i==par[curr]) continue;
            if (!visited[i]){
                visited[i] = true;
                t = visit(i);
                curr = i;
                done = true;
                break;
            }
        }
        if (!done){

            if (par[curr] == cent && visited[par[curr]]==0){
                dfs(curr, -1, 0);
                ll cent2 = centfind(curr, -1);
                if (cent2 == par[curr]){
                    t = visit(par[curr]);
                    curr = par[curr];
                    continue;
                }
                else return;

            }
            return;
        }


    }



}

Compilation message

interface.cpp: In function 'int main()':
interface.cpp:44:55: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     if(fread(T.data(), sizeof(int), 2 * N - 2, stdin) != 2 * N - 2) exit(0);
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
interface.cpp:50:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         int l = (numbers.size() == N ? N : 0);
      |                  ~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4356 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 13468 KB Correct
2 Correct 215 ms 13656 KB Correct
3 Correct 110 ms 14432 KB Correct
4 Correct 103 ms 15128 KB Correct
5 Incorrect 123 ms 14748 KB Not correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 8964 KB Correct
2 Correct 84 ms 9220 KB Correct
3 Correct 82 ms 8800 KB Correct
4 Correct 97 ms 11880 KB Correct
5 Correct 138 ms 11348 KB Correct
6 Correct 164 ms 11360 KB Correct
7 Correct 71 ms 8732 KB Correct
8 Correct 83 ms 8652 KB Correct
9 Correct 80 ms 8700 KB Correct
10 Correct 81 ms 8688 KB Correct
11 Correct 80 ms 8612 KB Correct
12 Correct 70 ms 8704 KB Correct
13 Correct 71 ms 8432 KB Correct
14 Correct 56 ms 7328 KB Correct
15 Correct 59 ms 7348 KB Correct
16 Correct 75 ms 8604 KB Correct
17 Correct 76 ms 8356 KB Correct
18 Correct 77 ms 8524 KB Correct
19 Correct 74 ms 8352 KB Correct
20 Correct 52 ms 7340 KB Correct
21 Correct 51 ms 7336 KB Correct
22 Correct 59 ms 7348 KB Correct
23 Correct 59 ms 7304 KB Correct
24 Correct 55 ms 7324 KB Correct
25 Correct 52 ms 7328 KB Correct
26 Correct 77 ms 8860 KB Correct
27 Correct 82 ms 8700 KB Correct
28 Correct 77 ms 8692 KB Correct
29 Correct 76 ms 8696 KB Correct
30 Correct 76 ms 9120 KB Correct
31 Correct 84 ms 8856 KB Correct
32 Correct 81 ms 8860 KB Correct
33 Correct 77 ms 8688 KB Correct
34 Correct 80 ms 8692 KB Correct
35 Correct 79 ms 8928 KB Correct
36 Correct 79 ms 8760 KB Correct
37 Correct 82 ms 8868 KB Correct
38 Correct 75 ms 8520 KB Correct
39 Correct 83 ms 8700 KB Correct
40 Correct 88 ms 8864 KB Correct
41 Correct 84 ms 8700 KB Correct
42 Correct 78 ms 8868 KB Correct
43 Correct 81 ms 8688 KB Correct
44 Correct 79 ms 8708 KB Correct
45 Correct 82 ms 8772 KB Correct
46 Correct 77 ms 8788 KB Correct
47 Correct 75 ms 9048 KB Correct
48 Correct 78 ms 8684 KB Correct
49 Correct 74 ms 8536 KB Correct
50 Correct 78 ms 8864 KB Correct
51 Correct 83 ms 8688 KB Correct
52 Correct 81 ms 9116 KB Correct
53 Correct 77 ms 8688 KB Correct
54 Correct 79 ms 8952 KB Correct
55 Correct 77 ms 8684 KB Correct
56 Correct 69 ms 8956 KB Correct
57 Correct 75 ms 8860 KB Correct
58 Correct 76 ms 8860 KB Correct
59 Correct 77 ms 9120 KB Correct
60 Correct 78 ms 8860 KB Correct
61 Correct 81 ms 8948 KB Correct
62 Correct 81 ms 8880 KB Correct
63 Correct 71 ms 8696 KB Correct
64 Correct 86 ms 8864 KB Correct
65 Correct 74 ms 8860 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4356 KB Correct
2 Correct 211 ms 13468 KB Correct
3 Correct 215 ms 13656 KB Correct
4 Correct 110 ms 14432 KB Correct
5 Correct 103 ms 15128 KB Correct
6 Incorrect 123 ms 14748 KB Not correct
7 Halted 0 ms 0 KB -