제출 #197474

#제출 시각아이디문제언어결과실행 시간메모리
197474dndhk어르신 집배원 (BOI14_postmen)C++14
55 / 100
579 ms34164 KiB
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_N = 500000;

int N, M;
vector<pii> gp[MAX_N+1];
bool chk[MAX_N+1];
bool vst[MAX_N+1];
vector<int> v;

void solve(int x){
	vst[x] = true;
	v.pb(x);
	while(!gp[x].empty() && chk[gp[x].back().second])	gp[x].pop_back();
	chk[gp[x].back().second] = true;
	if(vst[gp[x].back().first]){
		while(v.back()!=gp[x].back().first){
			printf("%d ", v.back());
			vst[v.back()] = false;
			v.pop_back();
		}
		vst[v.back()] = false;
		printf("%d\n", v.back()); v.pop_back();
		if(v.empty())	return;
		else solve(gp[x].back().first);
	}
	else	solve(gp[x].back().first);
}

int main(){
	scanf("%d%d", &N, &M);
	for(int i=1; i<=M; i++){
		int a, b; scanf("%d%d", &a, &b);
		gp[a].pb({b, i});
		gp[b].pb({a, i});
	}
	int idx = 1;
	while(idx<=N){
		while(!gp[idx].empty() && chk[gp[idx].back().second])	gp[idx].pop_back();
		if(gp[idx].empty())	idx++;
		else{
			int n = idx;
			while(1){
				vst[n] = true;
				v.pb(n);
				while(!gp[n].empty() && chk[gp[n].back().second])	gp[n].pop_back();
				chk[gp[n].back().second] = true;
				if(vst[gp[n].back().first]){
					while(v.back()!=gp[n].back().first){
						vst[v.back()] = false;
						printf("%d ", v.back());
						v.pop_back();
					}
					vst[v.back()] = false;
					printf("%d\n", v.back()); v.pop_back();
					if(v.empty())	break;
					else n = gp[n].back().first;
				}else{
					n = gp[n].back().first;
				}
			}
		}
	}
	return 0;
}

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

postmen.cpp: In function 'int main()':
postmen.cpp:39: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:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d%d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...