Submission #839098

#TimeUsernameProblemLanguageResultExecution timeMemory
839098cpptowinRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#define name "TASK"
#define fo(i,d,c) for(int i=d;i<=c;i++)
#define fod(i,c,d) for(int i=c;i>=d;i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout<<"\n";
#define int long long
#define inf 1000000000
#define pii pair<int,int>
#define vii vector<pii>
#define lb(x) x&-x
#define bit(i,j) ((i>>j)&1)
#define offbit(i,j) (i^(1<<j))
#define onbit(i,j) (i|(1<<j))
#define vi vector<int>
template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;}
using namespace std;
map<int,int> mp[maxn];
vii ke[maxn];
int a[maxn];
int b[maxn];
int n,k;
int ans = 1e18;
void dfs(int u,int par)
{
    mp[u][0] = 0;
    for(auto [v,w] : ke[u])
    {
        if(v == par) continue;
        dfs(v,u);
        a[v] = w;
        b[v]++;
        if(mp[u].size() < mp[v].size())
        {
            swap(mp[u],mp[v]);
            swap(a[u],a[v]);
            swap(b[u],b[v]);
        }
        for(auto it : mp[v])
        {
            int dist = it.fi + a[v];
            if(mp[u].count(k - dist - a[u]))
                ans = min(ans,mp[u][k - dist - a[u]] + it.se + b[u] + b[v]);
        }
        for(auto it : mp[v])
        {
            int dist = it.fi  + a[v] - a[u];
            if(mp[u].count(dist)) mp[u][dist] = min(mp[u][dist],it.se + b[v] - b[u]);
            else mp[u][dist] = it.se + b[v] - b[u];
        }
    }
}
main()
{
    if(fopen(name".inp","r"))
    {
       freopen(name".inp","r",stdin);
       freopen(name".out","w",stdout);
    }
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n >> k;
    fo(i,1,n - 1)
    {
        int u,v,w;
        cin >> u >> v >> w;
        ke[u].pb(v,w);
        ke[v].pb(u,w);
    }
    dfs(1,1);
    cout << (ans == 1e18 ? -1 : ans);
}

Compilation message (stderr)

race.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main()
      | ^~~~
race.cpp: In function 'int main()':
race.cpp:62:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |        freopen(name".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
race.cpp:63:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |        freopen(name".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccUvZyIP.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccCtpfAM.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccCtpfAM.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status