답안 #979984

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
979984 2024-05-11T18:45:52 Z vjudge1 봉쇄 시간 (IOI23_closing) C++17
0 / 100
995 ms 2097152 KB
#include "closing.h"
using namespace std;
#include <bits/stdc++.h>
#define pb push_back

using lli=long long;

int max_score(int N, int X, int Y, long long K,
              vector<int> U, vector<int> V, vector<int> W)
{
      int ans=0;
    vector<vector<pair<int,lli>>> adj (N);
    vector<vector<int>> mat (N, vector<int> (N, -1));
    for(int i=0; i<N-1; ++i){
        adj[U[i]].pb({V[i], W[i]});
        adj[V[i]].pb({U[i], W[i]});
        mat[U[i]][V[i]]=W[i];
        mat[V[i]][U[i]]=W[i];
    }
   
    int init=0;
    int last=0;
    int ant=0;
    while(adj[init].size()==2){
        if(adj[init][0].first!=ant){
            ant=init;
            init=adj[init][0].first;
        }
        else{
            ant=init;
            init=adj[init][1].first;
        }
    }
    ant=init;
    last=adj[init][0].first;
    while(adj[last].size()==2){
        if(adj[last][0].first!=ant){
            ant=last;
            last=adj[last][0].first;
        }
        else{
            ant=last;
            last=adj[last][1].first;
        }
    }
    
    vector<int> ord;
    int rec=init;
    ant=init;
    while(rec!=last){
    //    cout<<"rec: "<<rec<<endl;
        ord.pb(rec);
        if(adj[rec][0].first!=ant){
            ant=rec;
            rec=adj[rec][0].first;
        }
        else{
            ant=rec;
            rec=adj[rec][1].first;
        }
    }
    ord.pb(rec);
    vector<int> numb(N);
    for(int i=0; i<N; ++i){
        numb[ord[i]]=i;
    }
    if(numb[X]>numb[Y]){
        swap(X,Y);
    }
  
    /*
    for(int i=numb[X]; i>=0; --i){
        vector<int> values (N, 0);
        int cont=K;
        for(int a=numb[X]-1; a>=i; --a){
            values[a]=values[a+1]+mat[ord[a+1]][ord[a]];
            cont-=values[a];
        }
        if(cont<0) break;
        for(int j=numb[X]; j<N; ++j){
            for(int a=numb[X]+1; a<=j; ++a){
                values[a]=values[a-1]+mat[ord[a-1]][ord[a]];
                cont-=values[a];
            }
            if(cont<0) break;
            int aux=j-i+1;
            priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
            vector<bool> visited (N, false);
            pq.push({0, numb[Y]});
            
            while(!pq.empty()){
                int a=pq.top().first;
                int b=pq.top().second;
                pq.pop();
                if(visited[b]) continue;
                visited[b]=true;
                if(cont>=a){
                    cont-=a;
                    aux++;
                    if(b+1<N && !visited[b+1]){
                        pq.push({a+mat[ord[b]][ord[b+1]]-values[b+1], b+1});
                    }
                    if(b-1>=0 && !visited[b-1]){
                        pq.push({a+mat[ord[b]][ord[b-1]]-values[b-1], b-1});
                    }
                }
                else{
                    break;
                }
            }
            ans=max(ans, aux);
        }
     
    }*/
   return ans;


}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 995 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '0'
2 Halted 0 ms 0 KB -