답안 #103480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103480 2019-03-30T19:55:22 Z figter001 Simurgh (IOI17_simurgh) C++17
0 / 100
2 ms 384 KB
#include "simurgh.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int nax = 510;

int dsu[nax],in[nax];
int m,n;
vector<pair<int,int>> g[nax];
vector<int> u,v;

int find(int u){
	return u == dsu[u] ? u : dsu[u] = find(dsu[u]);
}

bool good(vector<int> ans){
	for(int i=0;i<n;i++)
		dsu[i] = i;
	for(int i=0;i<ans.size();i++){
		int id = ans[i];
		int a = u[id];
		int b = v[id];
		if(find(a) == find(b))
			continue;
		dsu[find(b)] = find(a);
	}
	for(int i=0;i<n;i++)
		if(find(i) != find(0))
			return 0;
	return 1;
}

vector<int> find_roads(int N, vector<int> U, vector<int> V) {
	vector<int> ans;
	u = U;
	v = V;
	n = N;
	m = u.size();

	for(int i=0;i<n;i++)
		dsu[i] = i;

	int lst;
	for(int i=0;i<m;i++){
		int a = u[i];
		int b = v[i];
		g[a].push_back({b,i});
		g[b].push_back({a,i});
		if(find(a) == find(b))
			continue;
		in[a]++;
		in[b]++;
		ans.push_back(i);
		dsu[find(b)] = find(a);
	}
	lst = count_common_roads(ans);
	for(int i=0;i<ans.size();i++){
		int id = ans[i];
		int a = u[id];
		int b = v[id];
		for(int j=0;j<m;j++){
			ans[i] = j;
			in[a]--;
			in[b]--;
			in[u[j]]++;
			in[v[j]]++;
			if(in[a] > 0 && in[b] > 0){
				int r = count_common_roads(ans);
				if(r < lst){
					ans[i] = id;
					break;
				}
				if(r > lst){
					lst = r;
					break;
				}
			}
			in[a]++;
			in[b]++;
			in[u[j]]--;
			in[v[j]]--;
			ans[i] = id;
		}
	}
	// for(int i : ans)
	// 	printf("%d ", i);
	// printf("\n");
	return ans;
}

Compilation message

simurgh.cpp: In function 'bool good(std::vector<int>)':
simurgh.cpp:23:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<ans.size();i++){
              ~^~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:61:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<ans.size();i++){
              ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB correct
2 Incorrect 2 ms 384 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB WA in grader: NO
2 Halted 0 ms 0 KB -