Submission #842111

# Submission time Handle Problem Language Result Execution time Memory
842111 2023-09-02T12:11:51 Z danikoynov Closing Time (IOI23_closing) C++17
8 / 100
120 ms 44356 KB
#include "closing.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 2e5 + 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[3010][3010 * 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;
    }
    ans = 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:101:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for (int i = 0; i < vec.size(); i ++)
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 11096 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 Correct 117 ms 37936 KB Output is correct
2 Correct 120 ms 44356 KB Output is correct
3 Correct 67 ms 13904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11100 KB Output is correct
2 Incorrect 2 ms 11100 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 2 ms 11100 KB Output is correct
2 Incorrect 2 ms 11100 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 2 ms 11100 KB Output is correct
2 Incorrect 2 ms 11100 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 2 ms 11096 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 2 ms 11096 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 2 ms 11096 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 2 ms 11096 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 2 ms 11096 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -