This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).begin(), (x).end()
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
#define fv(c) for(int (a) = (1); (a) <= (c); (a)++)
#define fz(c) for(int (a) = (0); (a) < (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--)
#define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
#define pb push_back
#define in insert
#define ss second
#define ff first
vector <pair<ll, ll>> v[1001];
ll a[1001], b[1001];
ll kk, mn = 1e9;
void dfs(int x)
{
for(auto it : v[x]){
if(it.first != x){
a[it.first] = a[x]+it.second;
b[it.first] = b[x]+1;
if(a[it.first] == kk)
mn = min(mn, b[it.first]);
dfs(it.first);
}
}
}
int best_path(int n, int k, int h[][2], int l[])
{
kk = k;
fp(i,1,n)
v[h[i][0]].pb({h[i][1], l[i]});//, cout << h[i][0] << " " << h[i][1] << " " << l[i] << "\n";
fp(i,0,n)
{
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
dfs(i);
/*fp(j,0,n)
cout << a[j] << " ";
cout << endl;
fp(j,0,n)
cout << b[j] << " ";
cout << "\nmn: " << mn << "\n";*/
}
mn = (mn == 1e9 ? -1 : mn);
return mn;
}
Compilation message (stderr)
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:10:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
| ^
race.cpp:38:2: note: in expansion of macro 'fp'
38 | fp(i,1,n)
| ^~
race.cpp:10:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
| ^
race.cpp:40:2: note: in expansion of macro 'fp'
40 | fp(i,0,n)
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |