답안 #847691

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
847691 2023-09-10T07:23:59 Z TheMiraiTraveller0711 봉쇄 시간 (IOI23_closing) C++17
8 / 100
185 ms 56224 KB
#include "closing.h"
#include <bits/stdc++.h>
// #include <vector>
using namespace std;
using ll = long long;

// Subtask Checker
class CheckSub1
{
private:
    vector<vector<pair<int, ll>>> adj;
    vector<bool> vis;
    vector<ll> dist;

    void DFS(int u, ll dd)
    {
        vis[u] = 1;
        dist[u] = dd;
        for (auto [v, w] : adj[u])
        {
            if (vis[v])
                continue;
            DFS(v, dd + w);
        }
    }

public:
    bool isSub1(int N, int X, int Y, long long K,
                vector<int> U, vector<int> V, vector<int> W)
    {
        adj.resize(N + 3);
        dist.resize(N + 3);
        vis.assign(N + 3, 0);
        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]});
        }
        DFS(X, 0);
        return (dist[Y] > 2 * K);
    }
};

/*
Subtask 1 :
*/
class Subtask1
{
private:
    vector<vector<pair<int, ll>>> adj;
    vector<bool> vis;
    void DFS(int u, ll dd, vector<ll> &dist)
    {
        vis[u] = 1;
        dist[u] = dd;
        for (auto [v, w] : adj[u])
        {
            if (vis[v])
                continue;
            DFS(v, dd + w, dist);
        }
    }

public:
    int getsol(int N, int X, int Y, long long K,
               vector<int> U, vector<int> V, vector<int> W)
    {
        adj.resize(N + 3);
        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]});
        }
        vector<ll> dist1(N + 3);
        vis.assign(N + 3, 0);
        DFS(X, 0, dist1);
        vector<ll> dist2(N + 3);
        vis.assign(N + 3, 0);
        DFS(Y, 0, dist2);

        vector<ll> adist;
        for (int i = 0; i < N; i++)
        {
            adist.push_back(dist1[i]);
            adist.push_back(dist2[i]);
        }
        sort(adist.begin(), adist.end());

        int pt = 0, ans = 0;
        ll cost = 0;
        while (pt < adist.size() && cost + adist[pt] <= K)
        {
            cost += adist[pt];
            pt++, ans++;
        }
        return ans;
    }
};

// Subtask2-8
class Subtask2
{
};

int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    CheckSub1 check;
    if (check.isSub1(N, X, Y, K, U, V, W))
    {
        Subtask1 sub1;
        return sub1.getsol(N, X, Y, K, U, V, W);
    }
    else
    {
        return -1;
    }
}

Compilation message

closing.cpp: In member function 'int Subtask1::getsol(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:91:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         while (pt < adist.size() && cost + adist[pt] <= K)
      |                ~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '-1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 185 ms 49592 KB Output is correct
2 Correct 170 ms 56224 KB Output is correct
3 Correct 95 ms 5352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 356 KB 1st lines differ - on the 1st token, expected: '3', found: '-1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 356 KB 1st lines differ - on the 1st token, expected: '3', found: '-1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 356 KB 1st lines differ - on the 1st token, expected: '3', found: '-1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '-1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '-1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '-1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '-1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '-1'
2 Halted 0 ms 0 KB -