Submission #231991

#TimeUsernameProblemLanguageResultExecution timeMemory
231991DodgeBallManTropical Garden (IOI11_garden)C++14
0 / 100
15 ms16896 KiB
#include <bits/stdc++.h> #include "gardenlib.h" #include "garden.h" using namespace std; const int N = 3e5 + 10; int chk[N], d[N], to[N], cyc; vector<int> vec, g[N], g2[N]; void dfs( int u ) { //printf("U %d\n",u); chk[u] = 1, vec.emplace_back( u ); for( int v : g[u] ) { if( !chk[v] ) d[v] = d[u] + 1, dfs( v ); else if( chk[v] == 1 ) for( int i = (int)vec.size() - 1 ; i >= 0 ; i-- ) { cyc++; if( vec[i] == v ) break; } } chk[u] = 2, vec.pop_back(); } //void answer( int x ) { printf("%d ",x); } void count_routes( int n, int m, int p, int r[][2], int q, int G[] ) { for( int i = 0 ; i < m ; i++ ) { if( g2[r[i][0]].size() < 2 ) g2[r[i][0]].emplace_back( r[i][1] ); if( g2[r[i][1]].size() < 2 ) g2[r[i][1]].emplace_back( r[i][0] ); } for(int i = 0; i < n; i++) if(g2[i].size() == 1) g2[i].emplace_back(g2[i][0]); //printf("\n"); for(int i = 0; i < n; i++) for(int j = 0; j < (int)g2[i].size(); j++) { int v = g2[i][j]; //printf("%d %d\n",i,v); if(g2[v][0] == i) v += n; g[v].emplace_back(i + (j ? n : 0)); } /*for( int i = 0 ; i < 2*n ; i++ ) printf("%d ",to[i]); printf("\n");*/ /*for( int i = 0 ; i < 2*n ; i++ ) g[i].clear(); for( int i = 0 ; i < 2*n ; i++ ) g[to[i]].emplace_back( i );*/ /*for( int i = 0 ; i < 2*n ; i++ ) { printf("%d : ",i); for( int v : g[i] ) printf("%d ",v); printf("\n"); } printf("\n");*/ vector<int> ans( q, 0 ); vec.clear(), memset( d, 0, sizeof d ), cyc = 0, memset( chk, 0, sizeof chk ); dfs( p ); //printf("%d\n",cyc); for( int i = 0 ; i < q ; i++ ) { for( int j = 0 ; j < n ; j++ ) { if( d[j] > G[i] ) continue ; if( cyc ) ans[i] += ( ( G[i] - d[j] ) % cyc == 0 ); else ans[i] += ( d[j] == G[i] ); } } vec.clear(), memset( d, 0, sizeof d ), cyc = 0, memset( chk, 0, sizeof chk ); dfs( p+n ); //printf("%d\n",cyc); for( int i = 0 ; i < q ; i++ ) { for( int j = 0 ; j < n ; j++ ) { if( d[j] > G[i] ) continue ; if( cyc ) ans[i] += ( ( G[i] - d[j] ) % cyc == 0 ); else ans[i] += ( d[j] == G[i] ); } // answer( ans[i] ); } //return ans; } /*int main() { int n, m, p, q, r[100][2], G[100]; scanf("%d %d %d %d",&n,&m,&p,&q); for( int i = 0 ; i < m ; i++ ) { scanf("%d %d",&r[i][0],&r[i][1]); } for( int i = 0 ; i < q ; i++ ) scanf("%d",&G[i]); count_routes( n, m, p, r, q, G ); }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...