답안 #134627

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134627 2019-07-23T05:52:53 Z dvdg6566 Simurgh (IOI17_simurgh) C++14
0 / 100
22 ms 3064 KB
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb emplace_back
#define mp make_pair
#define f first
#define s second
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()
#define MAXN 241

int N,a,b;
vpi V[MAXN];
vpi edgeList;
vi res,cur;
vpi tmp;
int p[MAXN];
int lowlink[MAXN], depth[MAXN];
int par(int x){return (x==p[x])?x:p[x] = par(p[x]);}
vi bridges;

void dfs(int x,int p){
	lowlink[x] = depth[x];
	for (auto v : V[x])if(v.f!=p){
		if (depth[v.f] != -1){
			lowlink[x] = min(lowlink[x], lowlink[v.f]);
			continue;
		}
		depth[v.f] = depth[x]+1;
		dfs(v.f,x);
		lowlink[x] = min(lowlink[x], lowlink[v.f]);
	}
}

bool isBridge(int x, int y){
	if (lowlink[x]<=lowlink[y]&&depth[x]>depth[y])return 0;
	if (lowlink[y]<=lowlink[x]&&depth[y]>depth[x])return 0;
	return 1;
}

std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
	N=n;
	for (int i=0;i<SZ(u);++i){
		a=u[i];b=v[i];
		V[a].pb(b,i);V[b].pb(a,i);
		edgeList.pb(a,b);
	}
	a=1;
	memset(depth,-1,sizeof(depth));
	depth[0]=0;
	dfs(0,0);
	// for (int i=0;i<N;++i)cout<<depth[i]<<' '<<lowlink[i]<<'\n';
	for (int i=0;i<SZ(u);++i){
		int a=edgeList[i].f;
		int b=edgeList[i].s;
		if (isBridge(a,b))bridges.pb(i);
	}
		for (auto i : bridges)res.pb(i);
	if (SZ(bridges) == N-1)return bridges;

	for (int i=0;i<N;++i){
		// We want to find all edges with index to a bigger node
		for (int j=0;j<N;++j)p[j]=j;
		cur.clear();
		tmp.clear();
		for (auto i : bridges){
			cur.pb(i);
			p[par(edgeList[i].f)] = par(edgeList[i].s);
		}
		for (int j=0;j<SZ(edgeList);++j){
			pi it = edgeList[j];
			if (it.f == i || it.s == i)continue;
			if (par(it.f) == par(it.s))continue;
			p[par(it.f)] = par(it.s);
			cur.pb(j);
		}
		for (auto x : V[i]){
			if (isBridge(i,x.f))continue;
			cur.pb(x.s);
			assert(SZ(cur) == N-1);
			// for (auto i : cur)cout<<i<<' ' ;cout<<'\n';
			int t = count_common_roads(cur);
			tmp.pb(x.s,t);
			cur.pop_back();
		}
		int lowest = 1e9;
		for (auto x : tmp)lowest = min(lowest,x.s);
		for (auto x : tmp){
			if (x.s > lowest)res.pb(x.f);
		}
		int hh = 0;
		for (auto x :tmp)hh=max(hh,x.s);
		if (hh == lowest){
			for (auto x:tmp)res.pb(x.f);
		}
		// for (auto x :tmp)cout<<x.f<<' '<<x.s<<'\n';
		// for (auto x:res)cout<<x<<' ';cout<<'\n';
	}
	sort(ALL(res));
	res.resize(unique(ALL(res)) - res.begin());
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB correct
2 Correct 2 ms 376 KB correct
3 Correct 2 ms 256 KB correct
4 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB correct
2 Correct 2 ms 376 KB correct
3 Correct 2 ms 256 KB correct
4 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB correct
2 Correct 2 ms 376 KB correct
3 Correct 2 ms 256 KB correct
4 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB correct
2 Correct 2 ms 376 KB correct
3 Runtime error 22 ms 3064 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB correct
2 Correct 2 ms 376 KB correct
3 Correct 2 ms 256 KB correct
4 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -