Submission #979767

# Submission time Handle Problem Language Result Execution time Memory
979767 2024-05-11T10:54:28 Z Mher777 Swapping Cities (APIO20_swap) C++17
37 / 100
2000 ms 9668 KB
#include "swap.h"
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <cassert>
#include <fstream>
using namespace std;
mt19937 rnd(7069);
typedef int itn;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef float fl;
typedef long double ld;
using vi = vector<int>;
using vll = vector<ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mpr make_pair
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define all(x) (x).begin(), (x).end()
const int dx[8] = { -1, 0, 1, 0, -1, -1, 1, 1 };
const int dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int MAX = int(1e9 + 5);
const ll MAXL = ll(1e18) + 5ll;
const ll MOD = ll(1000000007);
const ll MOD2 = ll(998244353);

const int N = 100005;
int p[N], sz[N], check[N], deg[N];
vector<pair<int, pii>> edge;
int n, m;

void init(int N, int M, vi U, vi V, vi W) {
    n = N, m = M;
    for (int i = 0; i < m; ++i) {
        edge.pub({ W[i],{U[i],V[i]} });
    }
    sort(all(edge));
}

void make_set(int x) {
    p[x] = x;
    sz[x] = 1;
    check[x] = deg[x] = 0;
}

int find_set(int x) {
    if (x == p[x]) return x;
    return p[x] = find_set(p[x]);
}

void union_sets(int x, int y) {
    x = find_set(x);
    y = find_set(y);
    if (x == y) return;
    if (sz[x] < sz[y]) swap(x, y);
    p[y] = x;
    sz[x] += sz[y];
    if (check[y]) check[x] = 1;
}

int getMinimumFuelCapacity(int X, int Y) {
    int x = X, y = Y;
    for (int i = 0; i < n; ++i) {
        make_set(i);
    }
    for (auto elem : edge) {
        int u = elem.ss.ff, v = elem.ss.ss;
        ++deg[u];
        ++deg[v];
        if (deg[u] >= 3) check[find_set(u)] = 1;
        if (deg[v] >= 3) check[find_set(v)] = 1;
        if (find_set(u) == find_set(v)) check[find_set(u)] = 1;
        union_sets(u, v);
        if (find_set(x) == find_set(y) && check[find_set(x)]) return elem.ff;
    }
    return -1;
}

/*
1.
5 6
0 1 4
0 2 4
1 2 1
1 3 2
1 4 10
2 3 3
3
1 2
2 4
0 1

2.
3 2
0 1 5
0 2 5
1
1 2

answers
1.
3
10
4

2.
-1
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 28 ms 3796 KB Output is correct
10 Correct 39 ms 4308 KB Output is correct
11 Correct 41 ms 4308 KB Output is correct
12 Correct 42 ms 4484 KB Output is correct
13 Correct 40 ms 4468 KB Output is correct
14 Execution timed out 2036 ms 4048 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2025 ms 6248 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 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 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 28 ms 3796 KB Output is correct
11 Correct 39 ms 4308 KB Output is correct
12 Correct 41 ms 4308 KB Output is correct
13 Correct 42 ms 4484 KB Output is correct
14 Correct 40 ms 4468 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 5 ms 1052 KB Output is correct
35 Correct 41 ms 4476 KB Output is correct
36 Correct 42 ms 4480 KB Output is correct
37 Correct 42 ms 4452 KB Output is correct
38 Correct 41 ms 4420 KB Output is correct
39 Correct 42 ms 4432 KB Output is correct
40 Correct 42 ms 4048 KB Output is correct
41 Correct 43 ms 4652 KB Output is correct
42 Correct 41 ms 4408 KB Output is correct
43 Correct 40 ms 4660 KB Output is correct
44 Correct 45 ms 4472 KB Output is correct
45 Correct 57 ms 7880 KB Output is correct
46 Correct 43 ms 4456 KB Output is correct
47 Correct 46 ms 4396 KB Output is correct
48 Correct 43 ms 4560 KB Output is correct
49 Correct 47 ms 8572 KB Output is correct
50 Correct 36 ms 4800 KB Output is correct
51 Correct 45 ms 5072 KB Output is correct
52 Correct 61 ms 8352 KB Output is correct
53 Correct 64 ms 7620 KB Output is correct
54 Correct 77 ms 9668 KB Output is correct
55 Correct 41 ms 5680 KB Output is correct
56 Correct 79 ms 9588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 28 ms 3796 KB Output is correct
10 Correct 39 ms 4308 KB Output is correct
11 Correct 41 ms 4308 KB Output is correct
12 Correct 42 ms 4484 KB Output is correct
13 Correct 40 ms 4468 KB Output is correct
14 Execution timed out 2036 ms 4048 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 28 ms 3796 KB Output is correct
11 Correct 39 ms 4308 KB Output is correct
12 Correct 41 ms 4308 KB Output is correct
13 Correct 42 ms 4484 KB Output is correct
14 Correct 40 ms 4468 KB Output is correct
15 Execution timed out 2036 ms 4048 KB Time limit exceeded
16 Halted 0 ms 0 KB -