Submission #969315

# Submission time Handle Problem Language Result Execution time Memory
969315 2024-04-25T00:14:54 Z angels Closing Time (IOI23_closing) C++17
0 / 100
169 ms 32336 KB
#include "closing.h"

#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>>a[200001];
void dfs(int x, long long int d, vector<long long int> &dist, bool visited[])
{
    visited[x]=1;
    dist[x]=d;
    for(int i=0; i<a[x].size(); i++)
    {
        if(!visited[a[x][i].first])
        {
            dfs(a[x][i].first, d+a[x][i].second, dist, visited);
        }
    }
}

int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    int n=N, x=X, y=Y;
    long long k=K;
    for(int i=0; i<n-1; i++)
    {
        a[U[i]].push_back({V[i], W[i]});
        a[V[i]].push_back({U[i], W[i]});
    }
    bool visited[n];
    memset(visited, false, sizeof(visited));
    vector<long long> dist(n), dist2(n);
    dfs(x, 0, dist, visited);
    memset(visited, false, sizeof(visited));
    dfs(y, 0, dist2, visited);
    /*long long int dist[2*n];
    int j=0, j1=n;
    for(int i=0; i<n; i++)
    {
        dist[j]=dist1[i];
        dist[j1]=dist2[i];
        j++; j1++;
    }*/
    dist.insert(dist.end(), dist2.begin(), dist2.end());
    sort(dist.begin(), dist.end());
    int sol=0, j=0;
    long long kk=0;
    while(kk+dist[j]<=k && j<dist.size())
    {
        kk+=dist[j];
        j++;
        sol++;
    }
    return sol;
}

Compilation message

closing.cpp: In function 'void dfs(int, long long int, std::vector<long long int>&, bool*)':
closing.cpp:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i=0; i<a[x].size(); i++)
      |                  ~^~~~~~~~~~~~
closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:46:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     while(kk+dist[j]<=k && j<dist.size())
      |                            ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4952 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 118 ms 27956 KB Output is correct
2 Correct 137 ms 32336 KB Output is correct
3 Incorrect 169 ms 11860 KB 2nd lines differ - on the 1st token, expected: '38', found: '45'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Incorrect 1 ms 4956 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 4956 KB Output is correct
2 Incorrect 1 ms 4956 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 4956 KB Output is correct
2 Incorrect 1 ms 4956 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 1 ms 4952 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 1 ms 4952 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 1 ms 4952 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 1 ms 4952 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 1 ms 4952 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -