Submission #116052

#TimeUsernameProblemLanguageResultExecution timeMemory
116052MAMBA어르신 집배원 (BOI14_postmen)C++17
100 / 100
340 ms41084 KiB
#include <bits/stdc++.h> 

using namespace std;

#define rep(i , j , k) for (int i = j; i < (int)k; i++)
#define pb push_back
typedef vector<int> vi;

constexpr int N = 5e5 + 10;

int n, m, a, b;

int ptr[N];
bitset<N> mark, mark2;

int shit, to[N << 1], pre[N << 1], last[N << 1], junk[N << 1];

inline void addEdge(int a , int b) {
	to[shit] = b; pre[shit] = last[a]; last[a] = shit++;
	to[shit] = a; pre[shit] = last[b]; last[b] = shit++;	
}

int st[N], R;
void dfs(int v) {
	while (last[v] != -1) {
		int id = last[v];
		last[v] = pre[id];
		if (!mark[id / 2]) {
			mark[id / 2] = true;
			dfs(to[id]);
		}
	}
	if (mark2[v]) {
		while (mark2[v]) {
			printf("%d" , st[R]);
			if (st[R] == v) printf("\n");
			else printf(" ");
			mark2[st[R]] = false;
			R--;
		}
	} 
	mark2[v] = true;
	st[++R] = v;

}

int main() {
	memset(last, -1, sizeof(last));
	scanf("%d%d" , &n , &m);
	rep(i , 0 , m) {
		scanf("%d%d" , &a , &b);
		addEdge(a , b);
	}

	dfs(1);

	return 0;
}

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d" , &n , &m);
  ~~~~~^~~~~~~~~~~~~~~~~~
postmen.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d" , &a , &b);
   ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...