답안 #969314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969314 2024-04-24T23:58:04 Z angels 봉쇄 시간 (IOI23_closing) C++17
0 / 100
165 ms 32272 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;
    long long kk=0;
    for(int i=0; i<dist.size(); i++)
    {
        kk+=dist[i];
        if(kk<=k)
            sol++;
        else
            break;
    }
    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:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=0; i<dist.size(); i++)
      |                  ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 27936 KB Output is correct
2 Correct 145 ms 32272 KB Output is correct
3 Incorrect 165 ms 11964 KB 2nd lines differ - on the 1st token, expected: '38', found: '45'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -