# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
963046 | Amr | Tropical Garden (IOI11_garden) | C++17 | 1 ms | 604 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 "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define sz size()
#define all(x) (x).begin(),(x).end()
const int N = 1002;
vector<pair<ll,ll> > v[N];
ll lst[N];
vector<ll> vec;
ll vis[N];
void dfs1(ll x)
{
if(vis[x]) return;
vis[x] = 1;
vec.push_back(x);
for(int i = 0; i < v[x].sz; i++)
{
dfs1(v[x][i].S);
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
for(int i = 0; i < M; i++)
{
ll x = R[i][0] , y = R[i][1];
v[x].push_back({i,y});
v[y].push_back({i,x});
}
for(int i = 0; i < N; i++) sort(all(v[i]));
dfs1(P);
if(vec.sz==2)
{
answer(1);
return;
}
ll ans = 0;
for(int i = 0; i < vec.sz; i++)
{
ll x = vec[i],par=N;
for(int i = 0; i < N; i++) lst[i] = 0;
// cout << x << ": " << endl;
ll cnt= G[0];
while(cnt--)
{
// cout << x << " ";
ll y = v[x][lst[x]].S;
if(v[x].sz==1) {par = x, x = y; continue;}
if(y!=par) lst[par] = 0,lst[x] = (lst[x]+1)%2;
else y = v[x][(lst[x]+1)%2].S;
par = x;
x = y;
}
//cout << endl;
if(x==P) ans++;
}
answer(ans); return;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |