Submission #984298

# Submission time Handle Problem Language Result Execution time Memory
984298 2024-05-16T12:51:51 Z rumbin Senior Postmen (BOI14_postmen) C++17
0 / 100
160 ms 11460 KB
#include <bits/stdc++.h>

using namespace std;

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

int t  = 1,sum=0;

void dfs(int u, int p, int s)
{
	int cur = u;
	while(!E[cur].empty())
	{
		auto i = E[cur].begin();
		while(*i == s && ((++i)--)!=E[cur].end())
			i++;
		P.push_back(cur);
		int v= *i;
		E[v].erase(E[v].find(cur));
		E[cur].erase(i);
		cur = v;
	}
	P.push_back(s);
}

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

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);
	S.assign(P.size(),-1);
	V.assign(N+1, -1);
	for(int i=0; i<P.size(); i++)
	{
		if(V[P[i]] != -1)
			S[V[P[i]]] = i;
		V[P[i]] = i;
	}
	V.assign(P.size(), 0);
	for(int i=0; i<P.size(); i++)
		if(!V[i]&&S[i] != -1)
			trace(i);
	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:64:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for(int i=0; i<P.size(); i++)
      |               ~^~~~~~~~~
postmen.cpp:71:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for(int i=0; i<P.size(); i++)
      |               ~^~~~~~~~~
postmen.cpp:74:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |  for(int i=0; i<A.size(); i++)
      |               ~^~~~~~~~~
postmen.cpp:76:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for(int j=0; j<A[i].size(); j++)
      |                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 876 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 5 ms 952 KB Output is correct
7 Correct 16 ms 2140 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 128 ms 11444 KB Output is correct
10 Correct 4 ms 860 KB Output is correct
11 Incorrect 2 ms 604 KB Some edges were not used
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 860 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 5 ms 856 KB Output is correct
7 Correct 16 ms 2084 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 160 ms 11212 KB Output is correct
10 Correct 4 ms 860 KB Output is correct
11 Incorrect 2 ms 604 KB Some edges were not used
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 388 KB Output is correct
4 Correct 4 ms 860 KB Output is correct
5 Correct 1 ms 356 KB Output is correct
6 Correct 5 ms 860 KB Output is correct
7 Correct 15 ms 1884 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 125 ms 11460 KB Output is correct
10 Correct 4 ms 856 KB Output is correct
11 Incorrect 2 ms 604 KB Some edges were not used
12 Halted 0 ms 0 KB -