답안 #359257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
359257 2021-01-26T14:24:14 Z amunduzbaev Simurgh (IOI17_simurgh) C++14
0 / 100
1 ms 620 KB
#include "simurgh.h"

#ifndef EVAL
#include "grader.cpp"
#endif

#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<ll> vll;
typedef vector<int> vii;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
 
const int N = 2500;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);

int used[N], ue[N], ans, nn, mm;
vpii edges[N];
vii qq;

void dfs(int u){
	used[u] = 1;
	for(auto x:edges[u]){
		if(used[x.ff]) continue;
		ue[x.ss] = 1;
		qq.pb(x.ss);
		dfs(x.ff);
	}
}
vii ss, res;
int fix[N];

void find (int u, pii gg, int p = -1){
	if(!res.empty()) return;
	if(u == gg.ff){
		int last = sz(ss)-1;
		while(last >= 0) res.pb(ss[last]), last--;
		return;
	}used[u] = 1;
	for(auto x:edges[u]){
		if(p == x.ff) continue;
		if(ue[x.ss]){
			ss.pb(x.ss);
			find(x.ff, gg, u);
		}
	}ss.pop_back();
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	nn = n, mm = sz(u);
	for(int i=0;i<sz(u);i++){
		edges[u[i]].pb({v[i], i});
		edges[v[i]].pb({u[i], i});
	}
	dfs(0);
	int ans = count_common_roads(qq);
	vii rr;
	for(int i=0;i<mm;i++){
		if(ue[i]) continue;
		ss.clear(), res.clear();
		memset(used, 0, sizeof used);
		find(u[i], {v[i], i});
		ue[i] = 1; 
		vpii tres;
		for(auto x:res){
			ue[x] = 0;
			vii tt;			
			for(int i=0;i<mm;i++) if(ue[i]) tt.pb(i);
			int tmp = count_common_roads(tt);
			tres.pb({tmp, x});
			ue[x] = 1;
		}
		ue[i] = 0;
		if(tres.empty()) continue;
		sort(all(tres));
		if(tres[0].ff == tres.back().ff){
			if(tres[0].ff > ans) fix[i] = 2;
			else fix[i] = 1;
			for(auto x:tres) fix[x.ss] = 1;
			continue;
		}
		fix[tres[0].ss] = 2;
		
		if(tres[0].ff == ans) fix[i] = 2;
		else fix[i] = 1;
		
		
		for(int i=1;i<sz(tres);i++){
			fix[tres[i].ss] = 1;
			if(tres[i].ff > tres[i-1].ff) continue;
			fix[tres[i].ss] = 2;
		}
	}
	
	for(int i=0;i<mm;i++){
		if(fix[i] == 2 || fix[i] == 0) rr.pb(i);
	}assert(sz(rr) == n-1);
	
	return rr;
}

/*

5 7
0 1
0 2
1 2
2 3
2 4
3 4
1 4 

1
3
5
6

*/
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 620 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 620 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 620 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB correct
2 Runtime error 1 ms 620 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 620 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -