Submission #842102

# Submission time Handle Problem Language Result Execution time Memory
842102 2023-09-02T12:05:33 Z danikoynov Closing Time (IOI23_closing) C++17
0 / 100
49 ms 10024 KB
#include "closing.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 3e3 + 10;

vector < pair < int, ll > > adj[maxn];
ll dist[2][maxn];
int n;

void bfs(int s, ll arr[])
{
    queue < int > q;
    for (int i = 0; i < n; i ++)
        arr[i] = -1;

    arr[s] = 0;
    q.push(s);
    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        for (pair < int, ll > nb : adj[v])
        {
            if (arr[nb.first] == -1)
            {
                arr[nb.first] = arr[v] + nb.second;
                q.push(nb.first);
            }
        }
    }
}
const ll inf = 1e18;

ll value[maxn];
ll dp[maxn][maxn * 2], sub[maxn], temp[maxn * 2];
int used[maxn];



vector < int > path;
bool get_path(int v, int p, int target)
{
    if (v == target)
    {
        path.push_back(v);
        return true;
    }

    for (pair < int, ll > nb : adj[v])
    {
        if (nb.first == p)
            continue;
        if (get_path(nb.first, v, target))
        {
            path.push_back(v);
            return true;
        }
    }
    return false;
}

int ans;

int max_score(int N, int X, int Y, long long K,
              vector<int> U, vector<int> V, vector<int> W)
{

    for (int i = 0; i < N; i ++)
    {
        dist[0][i] = dist[1][i] = 0;
        adj[i].clear();
        used[i] = 0;
        value[i] = 0;
    }
    n = N;
    for (int i = 0; i < N - 1; i ++)
    {
        adj[U[i]].push_back({V[i], W[i]});
        adj[V[i]].push_back({U[i], W[i]});
    }

    bfs(X, dist[0]);
    bfs(Y, dist[1]);

    path.clear();
    get_path(Y, -1, X);

    vector < ll > vec;
    for (int i = 0; i < N; i ++)
    {
        vec.push_back(dist[0][i]);
        vec.push_back(dist[1][i]);
    }

    sort(vec.begin(), vec.end());
    ll sum = 0;
    for (int i = 0; i < vec.size(); i ++)
    {
        sum += vec[i];
        if (sum > K)
            break;
        ans = max(ans, i + 1);
    }


    return ans;

}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:100:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |     for (int i = 0; i < vec.size(); i ++)
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 49 ms 10024 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -