Submission #1046094

# Submission time Handle Problem Language Result Execution time Memory
1046094 2024-08-06T10:03:54 Z batsukh2006 Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 26196 KB
#include "closing.h"
#include<iostream>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<math.h>
#include<vector>
#include<stdio.h>
#include<utility>
#include<iomanip>
#include<string.h>
#include<limits.h>
#include<algorithm>
#include<functional>
#include<unordered_map> 
using namespace std;
#define ss second
#define ff first
#define endl '\n'
vector<pair<int,int> > f,s;
vector<vector<pair<int,int> > > g;
void dfs1(int a, int p, int w){
    f.push_back({w,a});
    for(auto node: g[a]){
        if(node.ff!=p){
            dfs1(node.ff,a,w+node.ss);
        }
    }
}
void dfs2(int a, int p, int w){
    s.push_back({w,a});
    for(auto node: g[a]){
        if(node.ff!=p){
            dfs2(node.ff,a,w+node.ss);
        }
    }
}
int max_score(int n, int x, int y, long long k, vector<int> u, vector<int> v, vector<int> w){
    f.clear(),s.clear();
    g.clear(),g.resize(n);
    for(int i=0; i<w.size(); i++){
        g[u[i]].push_back({v[i],w[i]});
        g[v[i]].push_back({u[i],w[i]});
    }
    dfs1(x,-1,0);
    dfs2(y,-1,0);
    sort(f.begin(),f.end());
    sort(s.begin(),s.end());
    int ans=0,cur=0;
    long long sum=0;
    vector<int> vis(n);
    for(auto i: f){
        if(sum+i.ff<=k){
            cur++;
            sum+=i.ff;
            vis[i.ss]=i.ff;
            int cnt=cur;
            long long tmp=sum;
            for(auto j: s){
                if(tmp+j.ff<=k){
                    cnt++;
                    if(vis[j.ss]<j.ff) tmp+=j.ff-vis[j.ss];
                }
            }
            ans=max(ans,cnt);
        }
    }
    return ans;
}
// int main(){
// 	ios::sync_with_stdio(0);
// 	cin.tie(0);
// 	cout.tie(0);
    
// 	int T=1;
//     // cin>>T;
//     while(T--){
//         int n,x,y,k; cin>>n>>x>>y>>k;
//         vector<int> u(n-1),v(n-1),w(n-1);
//         for(int i=0; i<n-1; i++) cin>>u[i]>>v[i]>>w[i];
//         cout<<max_score(n,x,y,k,u,v,w)<<endl;
//     }
// 	return 0;
// }

Compilation message

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i=0; i<w.size(); i++){
      |                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 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 Execution timed out 1018 ms 26196 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '34', found: '33'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '34', found: '33'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '34', found: '33'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 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 0 ms 348 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 0 ms 348 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 0 ms 348 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 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -