Submission #1085875

# Submission time Handle Problem Language Result Execution time Memory
1085875 2024-09-08T23:17:18 Z sergio_sak Drivers (BOI24_drivers) C++14
100 / 100
304 ms 15412 KB
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <bit>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <time.h>
#include <random>
#include <inttypes.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3,Ofast")

#define EPS 1e-9
#define PI acos(-1)
#define MAXN 200005
#define MOD 1'000'000'007
#define INF 1'000'000'000'000

#define ll int64_t
#define int int32_t
#define short int16_t

#define si(n) if(scanf("%d", &n))
#define sl(n) scanf("%ld", &n);
#define sc(n) scanf("%c", &n);
#define sf(n) scanf("%f", &n);
#define slf(n) scanf("%lf", &n);

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define dbg(x) std::cerr << #x << ": " << x << std::endl;

typedef std::set<int> si;
typedef std::set<ll> sll;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<std::vector<int>> dvi;
typedef std::vector<std::vector<ll>> dvll;
typedef std::unordered_map<int , int> mi;
typedef std::unordered_map<ll , ll> mll;

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b) * b;}

struct edge {
    int start, end;
    int length;
    
    bool operator <(const edge &that) const {
        return this->length < that.length;
    }
};
edge edges[MAXN];
 
struct query {
    int id;
    int start, end;
    int length;
    
    const bool operator<(const query &that) const {
        return this->length < that.length;
    }
};
query queries[MAXN];

int N, M, Q;
bool res[MAXN];
int par[MAXN], size[MAXN];

//Union Psajimo
void DSU() {
    for(int i = 0; i <= N; ++i) {
        par[i] = i;
        size[i] = 1;
    }
}

int find(int a) {
    if(a == par[a]) return a;
    return par[a] = find(par[a]);
}

void unite(int a, int b) {
    a = find(a);
    b = find(b);

    if(size[a] < size[b]) std::swap(a, b);
    par[b] = a;
    size[a] += size[b];
}

bool same(int a, int b) {
    return find(a) == find(b);
}

signed main()
{
    // freopen("file.out", "w", stdout);
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    
    std::cin>>N>>M>>Q;
    DSU();

    for(int i = 0; i < M; ++i) {
        std::cin>>edges[i].start>>edges[i].end>>edges[i].length;
    }

    for(int i = 0; i < Q; ++i) {
        std::cin>>queries[i].start>>queries[i].end>>queries[i].length;
        queries[i].id = i;
    }

    std::sort(edges, edges + M);
    std::sort(queries, queries + Q);


    int indx = 0;
    for(int i = 0; i < Q; ++i) {
        while(edges[indx].length <= queries[i].length && indx < M) {
            unite(edges[indx].start, edges[indx].end);
            indx++;
        }

        res[queries[i].id] = same(queries[i].start, queries[i].end);
    }

    for(int i = 0; i < Q; ++i) {
        if(res[i]) std::cout<<"TAIP"<<std::endl;
        else std::cout<<"NE"<<std::endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 245 ms 7428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 8 ms 756 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 13 ms 952 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 12 ms 860 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 245 ms 7428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 8 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 245 ms 7428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 8 ms 756 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 13 ms 952 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 12 ms 860 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 8 ms 604 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 245 ms 7428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 8 ms 756 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 13 ms 952 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 12 ms 860 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 8 ms 604 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 304 ms 15412 KB Output is correct
42 Correct 16 ms 1372 KB Output is correct
43 Correct 13 ms 1372 KB Output is correct
44 Correct 13 ms 1628 KB Output is correct
45 Correct 19 ms 1624 KB Output is correct
46 Correct 15 ms 1112 KB Output is correct
47 Correct 183 ms 11860 KB Output is correct
48 Correct 18 ms 1624 KB Output is correct
49 Correct 272 ms 15188 KB Output is correct