Submission #103586

#TimeUsernameProblemLanguageResultExecution timeMemory
103586luciocfSenior Postmen (BOI14_postmen)C++14
38 / 100
1082 ms36480 KiB
#include <bits/stdc++.h>
#define gc getchar

using namespace std;

const int maxn = 5e5+10;

typedef pair<int, int> pii;

int qtd;

bool markEdge[maxn], mark[maxn];

vector<pii> grafo[maxn];
vector<int> ans[maxn];

stack<int> stk;

void dfs(int u)
{
	if (mark[u])
	{
		++qtd;

		while (true)
		{
			int v = stk.top();
			stk.pop();

			mark[v] = 0;
			ans[qtd].push_back(v);

			if (v == u) break;
		}
	}

	for (auto v: grafo[u])
	{
		if (!markEdge[v.second])
		{
			mark[u] = 1;
			stk.push(u);
			markEdge[v.second] = 1;

			dfs(v.first);
		}
	}
}

inline int scan(void)
{
	int n = 0, x = gc(), s =1;

	for (;x<'0'||x>'9';x=gc()) if(x=='-') s=-1;
	for (;x>='0'&&x<='9';x=gc()) n = (n<<3) + (n<<1) + x-'0';
	return n;
}

int main(void)
{
	int n, m;
	n = scan(), m = scan();

	for (int i = 1; i <= m; i++)
	{
		int u, v;
		u = scan(), v = scan();

		grafo[u].push_back({v, i});
		grafo[v].push_back({u, i});
	}

	dfs(1);

	for (int i = 1; i <= qtd; i++)
	{
		printf("%d", ans[i][0]);
		for (int j = 1; j < ans[i].size(); j++)
			printf(" %d", ans[i][j]);
		printf("\n");
	}
}

Compilation message (stderr)

postmen.cpp: In function 'int scan()':
postmen.cpp:52:23: warning: variable 's' set but not used [-Wunused-but-set-variable]
  int n = 0, x = gc(), s =1;
                       ^
postmen.cpp: In function 'int main()':
postmen.cpp:78:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 1; j < ans[i].size(); j++)
                   ~~^~~~~~~~~~~~~~~
postmen.cpp:61:6: warning: variable 'n' set but not used [-Wunused-but-set-variable]
  int n, m;
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...