# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
354396 | AmirElarbi | Tropical Garden (IOI11_garden) | C++14 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
#define vi vector<int>
#define vf vector<float>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1000
using namespace std;
int n,m,p,q,res,cur, aff;
vii r;
vi g,par;
void dfs(int u){
//cout << u << " ";
if(res > cur){ return;}
if(res == cur && u == p) {aff++;return;}
int p = 0;
bool parent = false;
for(int i = 0; i < m; i++){
if(r[i].fi == u || r[i].se == u){
int v = (r[i].fi == u) ? r[i].se : r[i].fi;
if(par[u] != v){
res++;
par[v] = u;
parent = false;
dfs(v);
break;
} else if (par[u] == v && par[v] != u){
p = v;
parent = true;
}
}
}
if(parent) {
res++;
par[p] = u;
dfs(p);
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
n = N;
m = M;
p = P;
for(int i = 0; i < m; i++){
r.pb(mp(R[i][0],R[i][1]));
}
q = Q;
for(int i = 0; i < q; i++){
g.pb(G[i]);
}
for(int i = 0; i < q; i++){
aff = 0;
for(int j = 0; j < m; j++){
par.assign(n,-1);
cur = g[i];
res = 0;
dfs(j) ;
//cout << endl;
}
answer(aff);
}
return 0;
}