Submission #881797

# Submission time Handle Problem Language Result Execution time Memory
881797 2023-12-02T01:59:11 Z djs100201 Thousands Islands (IOI22_islands) C++17
Compilation error
0 ms 0 KB
#include "islands.h"
#include <variant>
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using PP = pair<ll, P>;
const ll n_ = 2e5 + 505, inf = (ll)2e9 * (ll)1e9 + 7, mod = 998244353;
ll n, m, tc = 1, a, b, c, d, sum, x, y, z, base, ans, k;
vector<P>rev[n_];
ll prob[n_],out[n_],checked[n_];
set<P>v[n_],edge[n_];
P To[n_];
vector<int> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) {
	n=N,m=M;
    for(int i=0;i<m;i++){
		out[U[i]]++;
		v[U[i]].insert({V[i],i});
		rev[V[i]].push_back({U[i],i});
	}
	fill(prob,prob+n+1,1);
	//가능성이 존재한다.
	queue<ll>q;
	for(int i=1;i<=n;i++){
		if(out[i])continue;
		q.push(i);
	}
	while(q.size()){
		a=q.front();
		q.pop();
		prob[a]=0;
		for(auto nxt:rev[a]){
			out[nxt.first]--;
			v[nxt.first].erase(nxt);
			if(out[nxt.first]==0){
				q.push(nxt.first);
			}
		}
	}
	ll now=0;
	vector<int>ret,ret_rev;
	while(1){
		if(!out[now])return {-1};
		if(out[now]==1){
			ret.push_back((*v[now].begin()).second);
			ret_rev.push_back((*v[now].begin()).second);
			queue<ll>q;
			for(auto nxt:rev[now]){
				out[nxt.first]--;
				v[nxt.first].erase(nxt);
				if(out[nxt.first]==0)q.push(nxt.first);
			}
			out[now]=0;
			now=(*v[now].begin()).first;
		}
		else{
			
			for(int i=0;i<n;i++){
				if(i==now || !v[i].size())continue;
				auto cur=*v[i].begin();
				//v[i].clear();
				edge[i].insert(cur);
				//cout<<i<<' '<<cur.first<<' '<<cur.second<<endl;
				//v[i].insert(a);
			}
			auto a=*v[now].begin();
			//cout<<a<<' '<<b<<endl;
			x=now;
			edge[now].clear();
			edge[now].insert(a);
			for(int i=0;i<n;i++)To[i]={-1,-1};
			while(1){
				P nxt;
				//cout<<x<<endl;
				if(edge[x].size()==1){
					nxt=*edge[x].begin();
				}
				else{
					for(auto i:edge[x]){
						if(i!=To[x])nxt=i;
					}
				}
				To[nxt.first]={x,nxt.second};
				//cout<<x<<' '<<nxt.first<<' '<<nxt.second<<endl;
				edge[nxt.first].insert({x,nxt.second});
				edge[x].erase(nxt);
				ret.push_back(nxt.second);
				x=nxt.first;
				if(x==now)break;
			}
			edge[now].clear();
			auto it=v[now].end();
			it--;
			//cout<<a<<' '<<b<<endl;
			x=now;
			edge[now].insert(*it);
			for(int i=0;i<n;i++)To[i]={-1,-1};
			base=0;
			while(1){
				P nxt;
				//cout<<x<<endl;
				if(edge[x].size()==1){
					nxt=*edge[x].begin();
				}
				else{
					for(auto i:edge[x]){
						if(i!=To[x])nxt=i;
					}
				}
				To[nxt.first]={x,nxt.second};
				cout<<x<<' '<<nxt.first<<' '<<nxt.second<<endl;
				edge[nxt.first].insert({x,nxt.second});
				edge[x].erase(nxt);
				ret.push_back(nxt.second);
				x=nxt.first;
				if(x==now)break;
			}
			a=*v[now].begin();
			//cout<<a<<' '<<b<<endl;
			x=now;
			edge[now].clear();
			edge[now].insert(a);
			for(int i=0;i<n;i++)To[i]={-1,-1};
			while(1){
				P nxt;
				//cout<<x<<endl;
				if(edge[x].size()==1){
					nxt=*edge[x].begin();
				}
				else{
					for(auto i:edge[x]){
						if(i!=To[x])nxt=i;
					}
				}
				To[nxt.first]={x,nxt.second};
				//cout<<x<<' '<<nxt.first<<' '<<nxt.second<<endl;
				edge[nxt.first].insert({x,nxt.second});
				edge[x].erase(nxt);
				ret.push_back(nxt.second);
				x=nxt.first;
				if(x==now)break;
			}
			edge[now].clear();
			it=v[now].end();
			it--;
			//cout<<a<<' '<<b<<endl;
			x=now;
			edge[now].insert(*it);
			for(int i=0;i<n;i++)To[i]={-1,-1};
			base=0;
			while(1){
				P nxt;
				//cout<<x<<endl;
				if(edge[x].size()==1){
					nxt=*edge[x].begin();
				}
				else{
					for(auto i:edge[x]){
						if(i!=To[x])nxt=i;
					}
				}
				To[nxt.first]={x,nxt.second};
				cout<<x<<' '<<nxt.first<<' '<<nxt.second<<endl;
				edge[nxt.first].insert({x,nxt.second});
				edge[x].erase(nxt);
				ret.push_back(nxt.second);
				x=nxt.first;
				if(x==now)break;
			}
			break;
		}
	}
	reverse(all(ret_rev));
	for(auto i:ret_rev)ret.push_back(i);
    return ret;
}

Compilation message

islands.cpp:15:13: error: ambiguating new declaration of 'std::vector<int> find_journey(int, int, std::vector<int>, std::vector<int>)'
   15 | vector<int> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) {
      |             ^~~~~~~~~~~~
In file included from islands.cpp:1:
islands.h:4:38: note: old declaration 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)'
    4 | std::variant<bool, std::vector<int>> find_journey(
      |                                      ^~~~~~~~~~~~