Submission #878283

# Submission time Handle Problem Language Result Execution time Memory
878283 2023-11-24T07:56:46 Z boris_mihov Swapping Cities (APIO20_swap) C++17
0 / 100
2000 ms 13084 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) 
{
    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 2 ms 2652 KB Output is correct
5 Correct 3 ms 2652 KB Output is correct
6 Correct 4 ms 2652 KB Output is correct
7 Correct 3 ms 2648 KB Output is correct
8 Correct 5 ms 2648 KB Output is correct
9 Correct 177 ms 11116 KB Output is correct
10 Correct 540 ms 12332 KB Output is correct
11 Correct 653 ms 12532 KB Output is correct
12 Correct 808 ms 12304 KB Output is correct
13 Correct 911 ms 13084 KB Output is correct
14 Execution timed out 2063 ms 11192 KB Time limit exceeded
15 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 Execution timed out 2033 ms 10184 KB Time limit exceeded
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 2 ms 2652 KB Output is correct
5 Correct 3 ms 2652 KB Output is correct
6 Correct 4 ms 2652 KB Output is correct
7 Correct 3 ms 2648 KB Output is correct
8 Correct 5 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Incorrect 2 ms 2848 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 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 2 ms 2652 KB Output is correct
6 Correct 3 ms 2652 KB Output is correct
7 Correct 4 ms 2652 KB Output is correct
8 Correct 3 ms 2648 KB Output is correct
9 Correct 5 ms 2648 KB Output is correct
10 Correct 177 ms 11116 KB Output is correct
11 Correct 540 ms 12332 KB Output is correct
12 Correct 653 ms 12532 KB Output is correct
13 Correct 808 ms 12304 KB Output is correct
14 Correct 911 ms 13084 KB Output is correct
15 Incorrect 2 ms 2848 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 2 ms 2652 KB Output is correct
5 Correct 3 ms 2652 KB Output is correct
6 Correct 4 ms 2652 KB Output is correct
7 Correct 3 ms 2648 KB Output is correct
8 Correct 5 ms 2648 KB Output is correct
9 Correct 177 ms 11116 KB Output is correct
10 Correct 540 ms 12332 KB Output is correct
11 Correct 653 ms 12532 KB Output is correct
12 Correct 808 ms 12304 KB Output is correct
13 Correct 911 ms 13084 KB Output is correct
14 Execution timed out 2063 ms 11192 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 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 2 ms 2652 KB Output is correct
6 Correct 3 ms 2652 KB Output is correct
7 Correct 4 ms 2652 KB Output is correct
8 Correct 3 ms 2648 KB Output is correct
9 Correct 5 ms 2648 KB Output is correct
10 Correct 177 ms 11116 KB Output is correct
11 Correct 540 ms 12332 KB Output is correct
12 Correct 653 ms 12532 KB Output is correct
13 Correct 808 ms 12304 KB Output is correct
14 Correct 911 ms 13084 KB Output is correct
15 Execution timed out 2063 ms 11192 KB Time limit exceeded
16 Halted 0 ms 0 KB -