제출 #1354987

#제출 시각아이디문제언어결과실행 시간메모리
1354987monaxia경주 (Race) (IOI11_race)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#include <ext/random>
#include <ext/pb_ds/assoc_container.hpp>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#define pb push_back
#define ppb pop_back
#define fr first
#define sc second
#define all(v) v.begin(), v.end()
#define vektor vector

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

constexpr ull Mod = 1e9 + 7;
constexpr ull Mod2 = 1 + 7 * 17 * (1 << 23);
constexpr ull sqr = 320;
constexpr ld eps = 1e-12;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll random(ll l, ll r) {if(l <= r) return uniform_int_distribution <ll> (l, r)(rng); return -1;} 

int n, k;
vector <pair <int, int>> graph[200005];

int ch[200005], v[200005];

void prep(int node, int pr){
    ch[node] = 1;

    for(auto& [x, d] : graph[node]){
        if(x == pr || v[x]) continue;
        prep(x, node);

        ch[node] += ch[x];
    }
}

int getcen(int node, int pr, int sz){
    for(auto& [x, d] : graph[node]){
        if(x == pr || v[x]) continue;

        if(ch[x] * 2 > sz) return getcen(x, node, sz);
    }

    return node;
}

int cnt = 0;

gp_hash_table <ll, int> dp[200005];

int calc(int node, int pr, int root, ll dist, int depth){ 
    int ans = INT_MAX;
    if(dp[root].find(k - dist) != dp[root].end()) ans = min(ans, depth + dp[root][k - dist]);

    for(auto& [x, d] : graph[node]){
        if(v[x] || pr == x) continue;
        ans = min(ans, calc(x, node, root, dist + d, depth + 1));
    }

    return ans;
}   

void add(int node, int pr, int root, ll dist, int depth){
    if(dp[root].find(dist) != dp[root].end()) dp[root][dist] = min(dp[root][dist], depth);
    else dp[root][dist] = depth;

    for(auto& [x, d] : graph[node]){
        if(v[x] || pr == x) continue;
        add(x, node, root, dist + d, depth + 1);
    }
}

int dfs(int root){
    int ans = INT_MAX;
    for(auto& [x, d] : graph[root]){
        if(v[x]) continue;
        ans = min(ans, calc(x, root, root, d, 1));
        add(x, root, root, d, 1);
    }

    return ans;
}

int dnq(int root){
    cnt ++;
    if(cnt > 100) return INT_MAX;

    prep(root, -1);
    if(ch[root] == 1) return INT_MAX;

    root = getcen(root, -1, ch[root]);

    v[root] = 1;

    dp[root][0] = 0;
    int ans = dfs(root);

    for(auto& [x, d] : graph[root]){
        if(!v[x]) ans = min(ans, dnq(x));
    }

    return ans;
}

int best_path(int N, int K, int h[][2], int l[]){
    n = N;
    k = K;
    memset(v, 0, sizeof(v));

    for(int i = 0; i < n - 1; i ++){
        graph[h[i][0]].pb({h[i][1], l[i]});
        graph[h[i][1]].pb({h[i][0], l[i]});
    }

    int ans = dnq(0);

    if(ans >= 1e9) ans = -1;
    return ans;
}

void solve(){
    int n, k;
    cin >> n >> k;

    int edge[n + 1][2], val[n + 1];

    for(int i = 0; i < n - 1; i ++){
        cin >> edge[i][0] >> edge[i][1];
    }   

    for(int i = 0; i < n - 1; i ++) cin >> val[i];

    best_path(n, k, edge, val);
}  

main(){
    ios_base::sync_with_stdio(false);   
    cin.tie(NULL); 

    if(fopen("placeholder.inp", "r")){
        freopen("placeholder.inp", "r", stdin);
        freopen("placeholder.out", "w", stdout);
    }

    ll t = 1;

    // cin >> t;

    while(t --){
        solve();
        cout << "\n";
    }

    cerr << "Code time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}

// Whose eyes are those eyes?

컴파일 시 표준 에러 (stderr) 메시지

race.cpp:144:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  144 | main(){
      | ^~~~
race.cpp: In function 'int main()':
race.cpp:149:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  149 |         freopen("placeholder.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:150:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  150 |         freopen("placeholder.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc38usyg.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cca1q2aa.o:race.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status