コード例 #1
0
ファイル: main.cpp プロジェクト: kamiltalipov/295-a2
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;

	TGraph Graph (n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
		{
			bool x;
			cin >> x;
			if (x)
				Graph.Add(i, j);
		}
	
	bool ok = true;
	for (int i = 0; i < n; i++)
		if (!Graph.Used[i])
			Graph.DFS ( i, ok );

	if (ok)
		cout << "YES\n";

	fclose(stdin);
	fclose(stdout);

	return 0;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: kamiltalipov/295-a2
int main()
{
	freopen ("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);

	srand((unsigned)time(0));
	double n, m;
	double s1, s2;
	vector < pair < double, double > > center;
	vector < pair < double, double > > points;
	cin >> n >> m;
	cin >> s1 >> s2;
	
	TGraph Graph (n, m);
	TDSU DSU(n, m);

	for (int i = 0; i < n; i++)
		center.push_back( Box_Muller( 0, 0, s1 ) );

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			pair < double, double > tmp = Box_Muller ( center[i].first, center[i].second, s2 );
			points.push_back( tmp );
		}

	for (int i = 0; i < n * m; i++)
		for (int j = 0; j < n * m; j++)
			if (i != j)
				Graph.Add( i, j, dist( points[i], points[j] ) );
			
	sort(Graph.Vert.begin(), Graph.Vert.end());
	Graph.Make_Tree( DSU );

	Graph.Commie(0);
	Graph.Path.push_back( make_pair ( Graph.Path.back().second, 0) );

	double weight = 0;
	for (int i = 0; i < Graph.Path.size(); i++)
	{
		int v = Graph.Path[i].first;
		int u = Graph.Path[i].second;
		cout << points[v].first << ' ' << points[v].second << " : " << points[u].first << ' ' << points[u].second << endl;
		weight += dist ( points[v], points[u] );
	}

	cout << endl << weight << endl;

	fclose(stdin);
	fclose(stdout);
	return 0;
}