QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#58059#3711. Floyd-Warshallzjy2022Compile Error//C++1.5kb2022-10-24 17:08:032022-10-24 17:08:04

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-24 17:08:04]
  • Judged
  • [2022-10-24 17:08:03]
  • Submitted

answer

//QOJ #3711
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5,M=1e6+110;
int U[M],V[M],from[N],d[N],pos[N],dis[M-N][N],lg[N<<1],f[N<<1][20],E=0;
vector<int> G[N],T[N],vec;
queue<int> q;
int find(int x)
{
	if(x!=from[x])from[x]=find(from[x]);
	return from[x];
}
void bfs(int s)
{
	q.push(s);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		for(int v:G[u])
		{
			if(v==s||dis[s][v])continue;
			dis[s][v]=dis[s][u]+1;
			q.push(v);
		}
	}
	return;
}
void dfs(int u,int fa)
{
	f[pos[u]=++E][0]=d[u]=d[fa]+1;
	for(int v:T[u])if(v!=fa)dfs(v,u),f[++E][0]=d[u];
	return;
}
int MIN(int L,int R)
{
	if(L>R)swap(L,R);
	int k=lg[R-L+1];
	return min(f[L][k],f[R-(1<<k)+1][k]);
}
int main()
{
	int n,m,q;
	scanf("%d %d %d",&n,&m,&q);
	for(int i=1;i<=m;i++)
	{
		scanf("%d %d",&U[i],&V[i]);
		G[U[i]].push_back(V[i]);
		G[V[i]].push_back(U[i]);
	}
	for(int i=1;i<=n;i++)from[i]=i;
	for(int i=1;i<=m;i++)
	{
		int fu=find(U[i]),fv=find(V[i]);
		if(fu==fv)
		{
			vec.push_back(U[i]);
			continue;
		}
		T[U[i]].push_back(V[i]);
		T[V[i]].push_back(U[i]);
		from[fu]=fv;
	}
	for(int x:vec)bfs(x);
	dfs(1,0);
	for(int i=2;i<=E;i++)lg[i]=lg[i>>1]+1;
	for(int j=1;j<=lg[E];j++)for(int i=1;i+(1<<j)-1<=E;i++)f[i][j]=min(f[i][j-1],f[i+(1<<(j-1))][j-1]);
	while(q--)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		int ans=d[u]+d[v]-2*MIN(pos[u],pos[v]);
		for(int x:vec)ans=min(ans,dis[x][u]+dis[x][v]);
		printf("%d\n",ans);
	}
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:44:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |         scanf("%d %d %d",&n,&m,&q);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
answer.code:47:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |                 scanf("%d %d",&U[i],&V[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
answer.code:71:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   71 |                 scanf("%d %d",&u,&v);
      |                 ~~~~~^~~~~~~~~~~~~~~
/tmp/ccK68PE0.o: In function `find(int)':
answer.code:(.text+0xae): relocation truncated to fit: R_X86_64_PC32 against symbol `from' defined in .bss section in /tmp/ccK68PE0.o
/tmp/ccK68PE0.o: In function `dfs(int, int)':
answer.code:(.text+0x118): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccK68PE0.o
answer.code:(.text+0x11f): relocation truncated to fit: R_X86_64_PC32 against symbol `pos' defined in .bss section in /tmp/ccK68PE0.o
answer.code:(.text+0x1e8): relocation truncated to fit: R_X86_64_PC32 against symbol `pos' defined in .bss section in /tmp/ccK68PE0.o
answer.code:(.text+0x279): relocation truncated to fit: R_X86_64_PC32 against symbol `pos' defined in .bss section in /tmp/ccK68PE0.o
answer.code:(.text+0x303): relocation truncated to fit: R_X86_64_PC32 against symbol `pos' defined in .bss section in /tmp/ccK68PE0.o
answer.code:(.text+0x37f): relocation truncated to fit: R_X86_64_PC32 against symbol `pos' defined in .bss section in /tmp/ccK68PE0.o
answer.code:(.text+0x3fc): relocation truncated to fit: R_X86_64_PC32 against symbol `pos' defined in .bss section in /tmp/ccK68PE0.o
answer.code:(.text+0x46f): relocation truncated to fit: R_X86_64_PC32 against symbol `pos' defined in .bss section in /tmp/ccK68PE0.o
answer.code:(.text+0x4d8): relocation truncated to fit: R_X86_64_PC32 against symbol `pos' defined in .bss section in /tmp/ccK68PE0.o
answer.code:(.text+0x525): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status