제출 #980781

#제출 시각아이디문제언어결과실행 시간메모리
980781fv3어르신 집배원 (BOI14_postmen)C++14
55 / 100
632 ms184004 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
vector<int> adj[500000];
int start[500000];
unordered_set<int> c[500000];
vector<int> ep;
 
void euler(int index, int last)
{
	c[last].insert(index);
 
	for (; start[index] < adj[index].size();)
	{
		int node = adj[index][start[index]++]; 
		if (!c[node].count(index))
			euler(node, index);
	}
	ep.push_back(index);
}

int main()
{
	int N, M; cin >> N >> M; 
	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
 
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
 
	euler(0, 0);

	vector<int> occourence(N, -1);
	vector<int> linkedList(ep.size(), -1);
	iota(linkedList.begin(), linkedList.end(), 1);
 
	for (int i = 0; i < ep.size(); i++)
	{
		int value = ep[i];
 
		if (occourence[value] != -1)
		{
			int j = linkedList[occourence[value]];
			linkedList[occourence[value]] = i + 1;
 
			for (; j < i; j = linkedList[j])
			{
				cout << ep[j] + 1 << ' ';
				occourence[ep[j]] = -1;
			}
			cout << ep[i] + 1 << '\n';
			continue;
		}
		
		occourence[value] = i;
	} 
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

postmen.cpp: In function 'void euler(int, int)':
postmen.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for (; start[index] < adj[index].size();)
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
postmen.cpp: In function 'int main()':
postmen.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for (int i = 0; i < ep.size(); i++)
      |                  ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...