Submission #980764

# Submission time Handle Problem Language Result Execution time Memory
980764 2024-05-12T11:21:52 Z rumbin Senior Postmen (BOI14_postmen) C++17
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>

using namespace std;

vector<set<int>> E;
vector<vector<int>> A;
vector<int> V,P,S;

int t  = 1;
void dfs(int u, int p, int s)
{
	auto i = E[u].begin();
	while(!E[u].empty())
	{
		int v= *i;
		E[u].erase(i++);
		E[v].erase(E[v].find(u));
		dfs(v, u, s);
	}
	P.push_back(u);
//	cout<<u<<' ';
}

void trace(int i)
{
	int k = A.size();
	A.push_back({});
	A[k].push_back(P[i]);
	for(int j=i+1;j<S[i]; j++)
	{
		if(S[j] != -1 && S[j] < S[i])
		{
			trace(j);
			j = S[j];
			j--;
		}	
		else
			A[k].push_back(P[j]);
	}
}

int main()
{
	int N,M;
	cin>>N>>M;
	E.assign(N+1,{});
	V.assign(N+1,false);
	for(int i=0; i<M; i++)
	{
		int u,v;
		cin>>u>>v;
		E[u].insert(v);
		E[v].insert(u);
	}
	dfs(1,0,1);
	cout<<endl;
	S.assign(P.size(),-1);
	for(int i=0; i<P.size(); i++)
	{
		if(V[P[i]] != -1)
			S[V[P[i]]] = i;
		V[P[i]] = i;
	}
	trace(0);
	for(int i=0; i<A.size(); i++)
	{
		for(int j=0; j<A[i].size(); j++)
			cout<<A[i][j]<<' ';
		cout<<endl;
	}
}

Compilation message

postmen.cpp: In function 'int main()':
postmen.cpp:58:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for(int i=0; i<P.size(); i++)
      |               ~^~~~~~~~~
postmen.cpp:65:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i=0; i<A.size(); i++)
      |               ~^~~~~~~~~
postmen.cpp:67:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for(int j=0; j<A[i].size(); j++)
      |                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Some edges were not used
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Some edges were not used
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Some edges were not used
2 Halted 0 ms 0 KB -