#include "swap.h"
#include "grader.cpp"
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define int long long
const int NN = 1e5+5;
int sub, used[NN], found, pos[NN], is[NN];
vector<int> pref[NN];
vector<pair<int, int>> edges[NN];
vector<pair<int, int>> ss;
void dfs(int u, int p = -1){
if(used[u]){ found = 1; return; }
used[u] = 1;
//cout<<u<<" ";
for(auto x : edges[u]) {
if(x.ff == p) continue;
ss.pb({u, x.ss});
dfs(x.ff, u);
}
}
void init(int32_t N, int32_t M,
vector<int32_t> U, vector<int32_t> V, vector<int32_t> W) {
//cout<<"\n";
for(int i=0;i<M;i++){
edges[U[i]].pb({V[i], W[i]});
edges[V[i]].pb({U[i], W[i]});
}
if(M == N) sub = 1;
else sub = 2;
int last = 0;
for(int i=0;i<N;i++){
if(used[i]) continue;
ss.clear(), found = 0;
dfs(i);
//cout<<"\n";
if(found){
pref[last].pb(0);
ss.pop_back();
for(int j=0;j<sz(ss);j++){
is[ss[j].ff] = last+1;
pos[ss[j].ff] = j+1;
pref[last].pb(ss[j].ss);
} for(int j=1;j<=sz(ss);j++) pref[last][j] += pref[last][j-1];
last++;
}
}
}
/*
5 5
1 0 1
2 1 2
3 2 3
4 3 4
4 0 5
5
0 1
1 2
2 3
3 4
4 0
*/
int32_t getMinimumFuelCapacity(int32_t x, int32_t y) {
if(x > y) swap(x, y);
if(sub == 1){
if(is[x] != is[y] || !is[x]) return -1;
int l = is[x] - 1;
int i = pos[x], j = pos[y];
if(i > j) swap(i, j);
for(auto x : pref[l]) cout<<x<<" ";
//cout<<"\n";
//cout<<i<<" "<<j<<"\n";
return max(pref[l][j-1] - pref[l][i-1], pref[l][i-1] + pref[l][sz(pref[l])-1] - pref[l][j-1]);
} return -1;
}
Compilation message
swap.cpp: In function 'int32_t getMinimumFuelCapacity(int32_t, int32_t)':
swap.cpp:79:25: error: 'cout' was not declared in this scope
79 | for(auto x : pref[l]) cout<<x<<" ";
| ^~~~
swap.cpp:3:1: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
2 | #include "grader.cpp"
+++ |+#include <iostream>
3 | using namespace std;