Submission #842821

# Submission time Handle Problem Language Result Execution time Memory
842821 2023-09-03T11:51:22 Z helloworld1705 Closing Time (IOI23_closing) C++17
0 / 100
132 ms 76136 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
// #define int long long  
 
const int N = 2e6 + 5;
 
int dx[N] , dy[N];
 
vector <pair <int , long long>> adj[N];
vector <long long> vec = {};
 
void dfs_x(int u , int par) {
    for(auto [v , w] : adj[u]) {
        if(v == par) {
            continue;
        }
        dx[v] = dx[u] + w;
        dfs_x(v , u);
    }
}
 
void dfs_y(int u , int par) {
    for(auto [v , w] : adj[u]) {
        if(v == par) {
            continue;
        }
        dy[v] = dy[u] + w;
        dfs_y(v , u);
    }
}
 
int max_score(int N , int X , int Y , long long K, vector <int> U , vector <int> V , vector <int> W) {
    int sz = U.size();
    for(int i = 0; i < sz; i++) {
        adj[U[i]].emplace_back(V[i] , W[i]);
        adj[V[i]].emplace_back(U[i] , W[i]);
    }
    dfs_x(X , X);
    dfs_y(Y , Y);
    for(int i = 0; i < N; i++) {
        vec.push_back(dx[i]);
        vec.push_back(dy[i]);
    }
    sort(vec.begin() , vec.end());
    long long ans = 0;
    long long sum = 0;
    for(int x : vec) {
        sum += x;
        if(sum > K) break;
        ans++;
    }
    vec.clear();
    for(int i = 0; i < N; i++) {
    	adj[i].clear();
    	dx[i] = dy[i] = 0;
    }
    return ans;
}
 
// main() {
 
// 	ios_base::sync_with_stdio(0);
// 	cin.tie(0);	cout.tie(0);
 
// 	int n , x , y , k;
//     cin >> n >> x >> y >> k;
//     vector <int> u(n) , v(n) , w(n);
 
//     for(int i = 0; i < n - 1; i++) {
//     	cin >> u[i];
//     }
//     for(int i = 0; i < n - 1; i++) cin >> v[i];
//     for(int i = 0; i < n - 1; i++) cin >> w[i];
 
//     cout << max_score(n , x , y , k , u , v , w) << '\n';
// }
 
/*
7 0 2 10
0 0 1 2 2 5
1 3 2 4 5 6
2 3 4 2 5 3
*/
 
/*
4 0 3 20
0 1 2
1 2 3
18 1 19
*/
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 47704 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 132 ms 76136 KB 1st lines differ - on the 1st token, expected: '451', found: '400000'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 47708 KB Output is correct
2 Incorrect 10 ms 47704 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 47708 KB Output is correct
2 Incorrect 10 ms 47704 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 47708 KB Output is correct
2 Incorrect 10 ms 47704 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 47704 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 12 ms 47704 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 12 ms 47704 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 12 ms 47704 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 12 ms 47704 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -