답안 #794424

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794424 2023-07-26T14:13:35 Z firewater 장난감 기차 (IOI17_train) C++14
컴파일 오류
0 ms 0 KB
#include "train.h"
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include <cassert>
#define ll long long
#define MX 20230
using namespace std;
int n,m,tot,w,p[MX],a[MX],c[MX],cc[MX],h[MX],H[MX],fr[MX],cy[MX];
vector<int>ls,s[MX];
struct rec
{
	int to,nx;
}e[MX],E[MX];
void addl(int x,int y)
{
	e[++tot].to=y;
	e[tot].nx=h[x];
	h[x]=tot;
	return;
}
void addll(int x,int y)
{
	E[tot].to=y;
	E[tot].nx=H[x];
	H[x]=tot;
	return;
}
void dfs1(int x)
{
	p[x]=1;
	for(int i=h[x];i;i=e[i].nx){
		int y=e[i].to;
		if(p[y])continue;
		dfs1(y);
	}
	ls.push_back(x);
	return;
}
void dfs2(int x,int p)
{
	fr[x]=p;
	s[p].push_back(x);
	for(int i=H[x];i;i=E[i].nx){
		int y=E[i].to;
		if(fr[y])continue;
		dfs2(y,p);
	}
	return;
}
void dfs3(int x)
{
	cc[x]=1;
	for(int j=0;j<s[x].size();++j){
		int xx=s[x][j];
		for(int i=H[xx];i;i=E[i].nx){
			int y=E[i].to;
			if(cc[fr[y]])continue;
			dfs3(fr[y]);
		}
	}
	return;
}
std::vector<int> who_wins(std::vector<int> A, std::vector<int> C, std::vector<int> U, std::vector<int> V) {
	std::vector<int> ans(A.size());
	n=A.size();
	m=U.size();
	for(int i=1;i<=n;++i){
		a[i]=A[i-1];
		c[i]=C[i-1];
	}
	for(int i=0;i<m;++i){
		if(U[i]==V[i])cy[U[i]+1]=1;
		else{
			addl(U[i]+1,V[i]+1);
			addll(V[i]+1,U[i]+1);
		}
	}
	for(int i=1;i<=n;++i)
		p[i]=0;
	for(int i=1;i<=n;++i)
		if(!p[i])
			dfs1(i);
	reverse(ls.begin(),ls.end());
	for(int i=0;i<ls.size();++i)
		if(!fr[ls[i]])
			dfs2(ls[i],++w);
	for(int i=1;i<=n;++i)
		if(c[i]&&(s[fr[i]].size()>1||cy[i]==1))
			cc[fr[i]]=1;
	for(int i=1;i<=w;++i)
		if(cc[i])
			dfs3(i);
	for(int i=1;i<=n;++i)
		ans[i-1]=cc[fr[i]];
	return ans;
}





int main() {
	int n, m;
	assert(2 == scanf("%d %d", &n, &m));

	vector<int> a(n), r(n), u(m), v(m);

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &a[i]));

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &r[i]));

	for(int i = 0; i < m; i++)
		assert(2 == scanf("%d %d", &u[i], &v[i]));

	vector<int> res = who_wins(a, r, u, v);

	for(int i = 0; i < (int)res.size(); i++)
		printf(i ? " %d" : "%d", res[i]);
	printf("\n");

	return 0;
}

Compilation message

train.cpp: In function 'void dfs3(int)':
train.cpp:55:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for(int j=0;j<s[x].size();++j){
      |              ~^~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:86:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |  for(int i=0;i<ls.size();++i)
      |              ~^~~~~~~~~~
/usr/bin/ld: /tmp/ccedSt6s.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccfAGRls.o:train.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status