Submission #878286

# Submission time Handle Problem Language Result Execution time Memory
878286 2023-11-24T07:58:27 Z boris_mihov Swapping Cities (APIO20_swap) C++17
0 / 100
2000 ms 14372 KB
#include "swap.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
 
typedef long long llong;
const int MAXN = 100000 + 10;
const int INF  = 1e9;
 
int n, m;
bool vis[MAXN];
std::vector <std::pair <int,int>> g[MAXN];
 
int dfs(int node, int par, int dist)
{
    int res = 2;
    vis[node] = true;
    for (const auto &[u, d] : g[node])
    {
        if (d > dist) 
        {
            continue;
        }

        res--;
        if (vis[u])
        {
            continue;
        }
 
        res += dfs(u, node, dist);
    }
    
    return res;
}

void clearDFS(int node)
{
    vis[node] = false;
    for (const auto &[u, d] : g[node])
    {
        if (vis[u])
        {
            clearDFS(u);
        }
    }
}
 
bool check(int u, int v, int dist)
{
    bool res = (dfs(u, 0, dist) <= 0) && vis[v];
    clearDFS(u);
    return res;
}
 
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) 
{
    n = N; m = M;
    for (int i = 0 ; i < M ; ++i)
    {
        U[i]++; V[i]++;
        g[U[i]].emplace_back(V[i], W[i]);
        g[V[i]].emplace_back(U[i], W[i]);
    }
}
 
int getMinimumFuelCapacity(int x, int y) 
{
    if (m == n - 1)
    {
        return -1;
    }
    
    x++; y++;
    int l = 0, r = INF + 1, mid;
    while (l < r - 1)
    {
        mid = (l + r) / 2;
        if (!check(x, y, mid)) l = mid;
        else r = mid;
    }
 
    if (r > INF) return -1;
    return r;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 2 ms 2904 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 25 ms 7060 KB Output is correct
10 Correct 30 ms 8028 KB Output is correct
11 Correct 30 ms 7760 KB Output is correct
12 Correct 32 ms 8068 KB Output is correct
13 Correct 31 ms 8124 KB Output is correct
14 Correct 28 ms 7004 KB Output is correct
15 Correct 72 ms 14052 KB Output is correct
16 Correct 84 ms 14016 KB Output is correct
17 Correct 74 ms 14264 KB Output is correct
18 Correct 81 ms 14372 KB Output is correct
19 Execution timed out 2020 ms 8316 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Incorrect 72 ms 10344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 2 ms 2904 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Incorrect 1 ms 2652 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2904 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 25 ms 7060 KB Output is correct
11 Correct 30 ms 8028 KB Output is correct
12 Correct 30 ms 7760 KB Output is correct
13 Correct 32 ms 8068 KB Output is correct
14 Correct 31 ms 8124 KB Output is correct
15 Incorrect 1 ms 2652 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 2 ms 2904 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 25 ms 7060 KB Output is correct
10 Correct 30 ms 8028 KB Output is correct
11 Correct 30 ms 7760 KB Output is correct
12 Correct 32 ms 8068 KB Output is correct
13 Correct 31 ms 8124 KB Output is correct
14 Correct 28 ms 7004 KB Output is correct
15 Correct 72 ms 14052 KB Output is correct
16 Correct 84 ms 14016 KB Output is correct
17 Correct 74 ms 14264 KB Output is correct
18 Correct 81 ms 14372 KB Output is correct
19 Incorrect 72 ms 10344 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2904 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 25 ms 7060 KB Output is correct
11 Correct 30 ms 8028 KB Output is correct
12 Correct 30 ms 7760 KB Output is correct
13 Correct 32 ms 8068 KB Output is correct
14 Correct 31 ms 8124 KB Output is correct
15 Correct 28 ms 7004 KB Output is correct
16 Correct 72 ms 14052 KB Output is correct
17 Correct 84 ms 14016 KB Output is correct
18 Correct 74 ms 14264 KB Output is correct
19 Correct 81 ms 14372 KB Output is correct
20 Incorrect 72 ms 10344 KB Output isn't correct
21 Halted 0 ms 0 KB -