Submission #354395

#TimeUsernameProblemLanguageResultExecution timeMemory
354395AmirElarbiTropical Garden (IOI11_garden)C++14
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#define MAX_M 150002
#define optimize_io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int n, m, p;
int q, k;
int best[MAX_M];
int edges[MAX_M][2];
vector <int> E[MAX_M];
vector < pair <int, int> > out[MAX_M][2]; 
bool vis[MAX_M][2];

void createNewGraph( int node, int w ){
	
	if( vis[node][w] )
		return;
	vis[node][w] = 1;
	
	int nnode, nw;
	if( w == 1 )
		nnode = E[node].size() > 1 ? E[node][1] : E[node][0];
	else 
		nnode = best[node];
	
	if( best[nnode] == node )
		nw = 1;
	else 
		nw = 0;
		
	createNewGraph( nnode, nw );
	out[nnode][nw].push_back( make_pair( node, w ) );
	
}

int D[MAX_M][2][2], lenght[2] = { 1000000001, 1000000001 };
int visited[MAX_M][2], color;

void DFS( int node, int w, int d, int s ){
	
	if( visited[node][w] == color ){
		if( node == p && w == s )
			lenght[s] = d;
		return;
	}
	
	visited[node][w] = color;
	D[node][w][s] = d;
	for( int i = 0; i < out[node][w].size(); i++ )
		DFS( out[node][w][i].first, out[node][w][i].second, d + 1, s );
	
}

int main(){
	
	optimize_io
	
	cin >> n >> m >> p;
	for( int i = 0; i < n; i++ )
		best[i] = -1;
	for( int i = 1; i <= m; i++ ){
		cin >> edges[i][0] >> edges[i][1];
		E[ edges[i][0] ].push_back( edges[i][1] );
		E[ edges[i][1] ].push_back( edges[i][0] );
		if( best[ edges[i][0] ] == -1 )
			best[ edges[i][0] ] = edges[i][1];
		if( best[ edges[i][1] ] == -1 )
			best[ edges[i][1] ] = edges[i][0];
	}	
	
	for( int i = 0; i < n; i++ )
		for( int j = 0; j < 2; j++ )
			if( !vis[i][j] )
				createNewGraph( i, j );
	
	for( int i = 0; i < n; i++ )
		for( int j = 0; j < 2; j++ )
			for( int k = 0; k < 2; k++ )
				D[i][j][k] = 1000000001;
				
	color++;			
	DFS( p, 0, 0, 0 );
	color++;
	DFS( p, 1, 0, 1 );
	
	cin >> q;
	int res;
	for( int i = 1; i <= q; i++ ){
		cin >> k;
		res = 0;
		for( int j = 0; j < n; j++ ){
			if( k >= D[j][0][0] )
				res += ( ( k - D[j][0][0] ) % lenght[0] ) == 0 ? 1 : 0;
			if( k >= D[j][0][1] ) 
				res += ( ( k - D[j][0][1] ) % lenght[1] ) == 0 ? 1 : 0;
		}		
		cout << res ;
		if( i < q )
			cout << " ";
		else
			cout << "\n"; 
	}
	
	return 0;	
	
}

Compilation message (stderr)

garden.cpp: In function 'void DFS(int, int, int, int)':
garden.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for( int i = 0; i < out[node][w].size(); i++ )
      |                  ~~^~~~~~~~~~~~~~~~~~~~~
/tmp/ccBZmi3L.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccEdHu6b.o:garden.cpp:(.text.startup+0x0): first defined here
/tmp/ccBZmi3L.o: In function `main':
grader.cpp:(.text.startup+0x3b): undefined reference to `count_routes(int, int, int, int (*) [2], int, int*)'
collect2: error: ld returned 1 exit status