답안 #842800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
842800 2023-09-03T11:37:08 Z helloworld1705 봉쇄 시간 (IOI23_closing) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "closing.h"
using namespace std;
// /#define int long long  

const int N = 2e6 + 5;

int dx[N] , dy[N];

vector <pair <int , int>> adj[N];
vector <int> 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 , int k , vector <int> u , vector <int> v , vector <int> w) {
    for(int i = 0; i < u.size(); 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());
    int ans = 0;
    int 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
*/

Compilation message

closing.cpp: In function 'int max_score(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i = 0; i < u.size(); i++) {
      |                    ~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccvrKHBU.o: in function `main':
grader.cpp:(.text.startup+0x6a1): undefined reference to `max_score(int, int, int, long long, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status