Submission #1000779

# Submission time Handle Problem Language Result Execution time Memory
1000779 2024-06-18T08:37:58 Z uranhishig Race (IOI11_race) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mid(l,r) ((r+l)/2)
#define left(node) (node*2)
#define right(node) (node*2+1)
#define mx_int_prime 999999937
#define mod 1000000007
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define sqr(a) ((a) * (a))
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fastio cin.tie(0)->sync_with_stdio(0)
#define print(x) cout << x << "\n"
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
const int MAXN = 1e6 + 3;
vector<pii> adj[MAXN]; 
bool visited[MAXN]; 
int mi = INT_MAX;

void dfs(int node, int x, int y, int z) {
    visited[node] = true;
    if (x == y) {
        mi = min(mi, z);
    }
	else {
        for (auto neighbor : adj[node]) {
            int nextCity = neighbor.f;
            int length = neighbor.s;
            
            if (!visited[nextCity] && x + length <= y) {
                dfs(nextCity, x + length, y, z + 1);
            }
        }
    }  
    visited[node] = false; 
}

int run(int n, int k, int h[][2], int l[]) {
    rep(i, n-1) {
        int city1 = h[i][0], city2 = h[i][1], length = l[i];
        adj[city1].emplace_back(city2, length);
        adj[city2].emplace_back(city1, length);
    }
    mi = INT_MAX;
    rep(p, n) {
        memset(visited, false, sizeof(visited));
        dfs(p, 0, k, 0);
    }
    if (mi == INT_MAX) {
        return -1;
    } else {
        return mi;
    }
}

int main() {
	faster;
	int n, k;
	cin >> n >> k;
	int h[n][2];
	int l[n];
    
    rep(i, n-1) {
        cin >> h[i][0] >> h[i][1] >> l[i];
    }
    
    int ans = run(n, k, h, l);
    print(ans);
    
    return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccF3KhPi.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc4kEJNj.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc4kEJNj.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