답안 #578167

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578167 2022-06-16T06:42:27 Z handlename 게임 (APIO22_game) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
const int MOD=1e9+7;
int n,k;
vector<int> adj[300001],rev[300001];
struct node{
	node *l,*r;
	//left node stores stuff which can reach m
	//right node stores stuff which m can reach
	int s,m,e;
	unordered_set<int> stuff;
	node(int ss,int ee){
		s=ss;
		e=ee;
		m=(s+e)/2;
		if (s<e){
			l=new node(s,m);
			r=new node(m+1,e);
			for (int i=s;i<=m;i++) l->stuff.insert(i);
			for (int i=m;i<=e;i++) r->stuff.insert(i);
		}
		if (s==e){
			l=new node(s,-1);
			r=new node(s,-1);
			l->stuff.insert(s);
			r->stuff.insert(s);
		}
	}
	
	bool upd(int u,int v){
		if (e==-1) return false;
		/*
		cout<<"update "<<s<<' '<<m<<' '<<e<<' '<<u<<' '<<v<<'\n';
		cout<<"left: ";
		for (auto i:l->stuff) cout<<i<<' ';
		cout<<'\n';
		cout<<"right: ";
		for (auto i:r->stuff) cout<<i<<' ';
		cout<<'\n';
		*/
		bool uleft=(l->stuff.find(u)!=l->stuff.end());
		bool uright=(r->stuff.find(u)!=r->stuff.end());
		bool vleft=(l->stuff.find(v)!=l->stuff.end());
		bool vright=(r->stuff.find(v)!=r->stuff.end());
		if (uright){
			if (vleft) return true;
			if (vright) return r->upd(u,v);
			r->stuff.insert(v);
			if (r->upd(u,v)) return true;
			for (auto i:adj[v]){
				if (upd(v,i)) return true;
			}
		}
		if (vleft){
			if (uleft) return l->upd(u,v);
			l->stuff.insert(u);
			if (l->upd(u,v)) return true;
			for (auto i:rev[u]){
				if (upd(i,u)) return true;
			}
		}
		return false;
	}
}*root;
void init(int N,int K){
	n=N;
	k=K;
	for (int i=1;i<k;i++){
		//adj[i].pb(i+1);
		//rev[i+1].pb(i);
	}
	root=new node(1,k);
}
int add_teleporter(int u,int v){
	u++;
	v++;
	adj[u].pb(v);
	rev[v].pb(u);
	if (u>=v && u<=k) return 1;
	if (u==v) return 0;
	return root->upd(u,v);
}
void runtc(){
	int N,M,K;
	cin>>N>>M>>K;
	init(N,K);
	for (int i=1;i<=M;i++){
		int u,v;
		cin>>u>>v;
		//cout<<i<<' '<<add_teleporter(u,v)<<'\n';
		if (add_teleporter(u,v)==1) cout<<i<<'\n';
	}
}
int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    freopen("input1.in","r",stdin);
    //freopen("output1.out","w",stdout);
    int tc;
    //cin>>tc;
    tc=1;
    for (int i=1;i<=tc;i++){
        //cout<<"Case #"<<i<<": ";
        runtc();
    }
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:99:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |     freopen("input1.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccsLGEht.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cce1v1ls.o:game.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status