Submission #963136

#TimeUsernameProblemLanguageResultExecution timeMemory
963136AmrTropical Garden (IOI11_garden)C++17
0 / 100
3 ms5212 KiB
#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; const int Log = 32; vector<pair<ll,ll> > v[N]; ll lst[N]; vector<ll> vec; ll vis[N]; pair<ll,ll> sp[N][Log][2]; 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; } for(int i = 0; i < vec.sz; i++) { ll x = vec[i]; ll y = v[x][0].S; ll m = -1; if(v[y][0].S==x) m = 0; else if(v[y][1].S==x) m = 1; sp[x][0][0] = {y,m}; if(v[x].sz==1) {sp[x][0][1] = {-1,-1}; continue;} m = -1; y = v[x][1].S; if(v[y][0].S==x) m = 0; else if(v[y][1].S==x) m = 1; sp[x][0][1] = {y,m}; } for(int j = 1; j < Log; j++) { for(int i = 0; i < vec.sz; i++) { ll x = vec[i]; ll y = sp[x][j-1][0].F,m=0; if(sp[y][0][1].F!=-1&&sp[x][j-1][0].S==0) m = 1; sp[x][j][0] = sp[sp[x][j-1][0].F][j-1][m]; if(sp[x][0][1].F!=-1) { ll y = sp[x][j-1][0].F,m=0; if(sp[y][0][1].F!=-1&&sp[x][j-1][1].S==0) m = 1; sp[x][j][1] = sp[sp[x][j-1][1].F][j-1][m]; } } } /*for(int i = 0; i < N; i++){ for(int j = 0; j < 3; j++) { cout << sp[i][j][0].F << " " << sp[i][j][1].F << endl; } cout << endl; }*/ ll ans = 0; for(int i = 0; i < vec.sz; i++) { ll x = vec[i], y = 0; ll k = G[0]; for(int j = Log-1; j >= 0; j--) { if(k<(1LL<<j)) continue; k-=(1LL<<j); ll x2 = sp[x][j][y].F,m = sp[x][j][y].S; if(m==0&&sp[x2][0][1].F!=-1) m = 1; else m = 0; x = x2, y = m; } //cout << x << " "; if(x==P) ans++; } answer(ans); }

Compilation message (stderr)

garden.cpp: In function 'void dfs1(ll)':
garden.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i = 0; i < v[x].sz; i++)
      |                      ^
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i = 0; i < vec.sz; i++)
      |                      ^
garden.cpp:62:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for(int i = 0; i < vec.sz; i++)
      |                          ^
garden.cpp:88:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for(int i = 0; i < vec.sz; i++)
      |                          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...