Submission #157784

# Submission time Handle Problem Language Result Execution time Memory
157784 2019-10-12T22:29:04 Z Lawliet Pictionary (COCI18_pictionary) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 100010;
const int INF = 1000000010;

int n, m, q;

int pai[MAX];
int prof[MAX];
int edge[MAX];	

int find(int cur)
{
	if(pai[ cur ] == cur) return cur;
	return find( pai[ cur ] );
}

void join(int U, int V, int W)
{
	U = find( U ); V = find( V );

	if( U == V ) return;

	if( prof[ U ] < prof[ V ] ) swap( U , V );

	pai[ V ] = U;
	edge[ V ] = W;
	if(prof[ U ] == prof[ V ]) prof[ U ]++;
}

int maxPath(int U, int V)
{
	int ans = 0;

	while( U != V )
	{
		if( edge[ U ] < edge[ V ] )
		{
			ans = max(ans , edge[ U ]);
			U = pai[ U ];
		}
		else
		{
			ans = max(ans , edge[ V ]);
			V = pai[ V ];
		}
	}

	return ans;
}

int main()
{
	scanf("%d %d %d",&n,&m,&q);

	for(int i = 1 ; i <= n ; i++)
	{
		pai[ i ] = i;
		edge[ i ] = INF;
	}

	for(int i = m ; i >= 1 ; i--)
		for(int j = i ; j <= n ; j += i) join(i , j , m - i + 1);

	for(int i = 1 ; i <= q ; i++)
	{
		int U, V;
		scanf("%d %d",&U,&V);

		printf("%d\n",maxPath( U , V ));
	}
}#include <bits/stdc++.h>

using namespace std;

const int MAX = 100010;
const int INF = 1000000010;

int n, m, q;

int pai[MAX];
int prof[MAX];
int edge[MAX];	

int find(int cur)
{
	if(pai[ cur ] == cur) return cur;
	return find( pai[ cur ] );
}

void join(int U, int V, int W)
{
	U = find( U ); V = find( V );

	if( U == V ) return;

	if( prof[ U ] < prof[ V ] ) swap( U , V );

	pai[ V ] = U;
	edge[ V ] = W;
	if(prof[ U ] == prof[ V ]) prof[ U ]++;
}

int maxPath(int U, int V)
{
	int ans = 0;

	while( U != V )
	{
		if( edge[ U ] < edge[ V ] )
		{
			ans = max(ans , edge[ U ]);
			U = pai[ U ];
		}
		else
		{
			ans = max(ans , edge[ V ]);
			V = pai[ V ];
		}
	}

	return ans;
}

int main()
{
	scanf("%d %d %d",&n,&m,&q);

	for(int i = 1 ; i <= n ; i++)
	{
		pai[ i ] = i;
		edge[ i ] = INF;
	}

	for(int i = m ; i >= 1 ; i--)
		for(int j = i ; j <= n ; j += i) join(i , j , m - i + 1);

	for(int i = 1 ; i <= q ; i++)
	{
		int U, V;
		scanf("%d %d",&U,&V);

		printf("%d\n",maxPath( U , V ));
	}
}

Compilation message

pictionary.cpp:74:2: error: stray '#' in program
 }#include <bits/stdc++.h>
  ^
pictionary.cpp:74:3: error: 'include' does not name a type
 }#include <bits/stdc++.h>
   ^~~~~~~
pictionary.cpp:78:11: error: redefinition of 'const int MAX'
 const int MAX = 100010;
           ^~~
pictionary.cpp:5:11: note: 'const int MAX' previously defined here
 const int MAX = 100010;
           ^~~
pictionary.cpp:79:11: error: redefinition of 'const int INF'
 const int INF = 1000000010;
           ^~~
pictionary.cpp:6:11: note: 'const int INF' previously defined here
 const int INF = 1000000010;
           ^~~
pictionary.cpp:81:5: error: redefinition of 'int n'
 int n, m, q;
     ^
pictionary.cpp:8:5: note: 'int n' previously declared here
 int n, m, q;
     ^
pictionary.cpp:81:8: error: redefinition of 'int m'
 int n, m, q;
        ^
pictionary.cpp:8:8: note: 'int m' previously declared here
 int n, m, q;
        ^
pictionary.cpp:81:11: error: redefinition of 'int q'
 int n, m, q;
           ^
pictionary.cpp:8:11: note: 'int q' previously declared here
 int n, m, q;
           ^
pictionary.cpp:83:12: error: redefinition of 'int pai [100010]'
 int pai[MAX];
            ^
pictionary.cpp:10:5: note: 'int pai [100010]' previously declared here
 int pai[MAX];
     ^~~
pictionary.cpp:84:13: error: redefinition of 'int prof [100010]'
 int prof[MAX];
             ^
pictionary.cpp:11:5: note: 'int prof [100010]' previously declared here
 int prof[MAX];
     ^~~~
pictionary.cpp:85:13: error: redefinition of 'int edge [100010]'
 int edge[MAX]; 
             ^
pictionary.cpp:12:5: note: 'int edge [100010]' previously declared here
 int edge[MAX]; 
     ^~~~
pictionary.cpp: In function 'int find(int)':
pictionary.cpp:87:5: error: redefinition of 'int find(int)'
 int find(int cur)
     ^~~~
pictionary.cpp:14:5: note: 'int find(int)' previously defined here
 int find(int cur)
     ^~~~
pictionary.cpp: In function 'void join(int, int, int)':
pictionary.cpp:93:6: error: redefinition of 'void join(int, int, int)'
 void join(int U, int V, int W)
      ^~~~
pictionary.cpp:20:6: note: 'void join(int, int, int)' previously defined here
 void join(int U, int V, int W)
      ^~~~
pictionary.cpp: In function 'int maxPath(int, int)':
pictionary.cpp:106:5: error: redefinition of 'int maxPath(int, int)'
 int maxPath(int U, int V)
     ^~~~~~~
pictionary.cpp:33:5: note: 'int maxPath(int, int)' previously defined here
 int maxPath(int U, int V)
     ^~~~~~~
pictionary.cpp: In function 'int main()':
pictionary.cpp:127:5: error: redefinition of 'int main()'
 int main()
     ^~~~
pictionary.cpp:54:5: note: 'int main()' previously defined here
 int main()
     ^~~~
pictionary.cpp: In function 'int main()':
pictionary.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
pictionary.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&U,&V);
   ~~~~~^~~~~~~~~~~~~~~
pictionary.cpp: In function 'int main()':
pictionary.cpp:129:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
pictionary.cpp:143:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&U,&V);
   ~~~~~^~~~~~~~~~~~~~~