답안 #980194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
980194 2024-05-12T00:54:43 Z vjudge1 봉쇄 시간 (IOI23_closing) C++17
0 / 100
1000 ms 218984 KB
#include "closing.h"
#include <bits/stdc++.h>
#include <vector>
#include <queue>
using namespace std;

struct ari{
    int node;
    long long w;
};

struct tpos{
    int node;
    long long cnt;
    bool x;
};

bool operator <(const tpos &a, const tpos &b){
    return a.cnt>b.cnt;
}

int n;
long long k;
long long cnt;
int ans;
long long memo[200000];
vector<vector<ari>> adj;
priority_queue<tpos> q;

void dfs(){
    tpos t, ta;
    while(!q.empty() && cnt<k){
        t=q.top(); q.pop();
        if(memo[t.node]!=0){
            if(memo[t.node]<t.cnt){
                if(cnt+t.cnt-memo[t.node]<=k){
                    cnt+=t.cnt-memo[t.node];
                    memo[t.node]=t.cnt;
                }
                else{
                    continue;
                }
            }
        }
        else{
            if(cnt+t.cnt<=k){
                cnt+=t.cnt;
                memo[t.node]=t.cnt;
            }
            else
                continue;
        }
        ans++;
        for(auto h: adj[t.node]){
            q.push({h.node, t.cnt+h.w});
        }
    }
    while(!q.empty())
        q.pop();
}

int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W){   
    n=N;
    k=K;
    ans=2;
    cnt=0;
    adj.clear();
    adj.resize(n);
    for(int i=0; i<n; i++)
        memo[i]=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]});
    }
    for(int i=0; i<adj[X].size(); i++){
        q.push({adj[X][i].node, adj[X][i].w});
    }
    for(int i=0; i<adj[Y].size(); i++){
        q.push({adj[Y][i].node, adj[Y][i].w});
    }
    dfs();
    return ans;
}

Compilation message

closing.cpp: In function 'void dfs()':
closing.cpp:31:13: warning: unused variable 'ta' [-Wunused-variable]
   31 |     tpos t, ta;
      |             ^~
closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:76:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ari>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int i=0; i<adj[X].size(); i++){
      |                  ~^~~~~~~~~~~~~~
closing.cpp:79:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ari>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i=0; i<adj[Y].size(); i++){
      |                  ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1061 ms 218984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Incorrect 3 ms 792 KB 1st lines differ - on the 1st token, expected: '30', found: '11512'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Incorrect 3 ms 792 KB 1st lines differ - on the 1st token, expected: '30', found: '11512'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Incorrect 3 ms 792 KB 1st lines differ - on the 1st token, expected: '30', found: '11512'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Incorrect 3 ms 792 KB 1st lines differ - on the 1st token, expected: '30', found: '11512'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Incorrect 3 ms 792 KB 1st lines differ - on the 1st token, expected: '30', found: '11512'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Incorrect 3 ms 792 KB 1st lines differ - on the 1st token, expected: '30', found: '11512'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Incorrect 3 ms 792 KB 1st lines differ - on the 1st token, expected: '30', found: '11512'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Incorrect 3 ms 792 KB 1st lines differ - on the 1st token, expected: '30', found: '11512'
4 Halted 0 ms 0 KB -