제출 #832699

#제출 시각아이디문제언어결과실행 시간메모리
832699serifefedartar어르신 집배원 (BOI14_postmen)C++17
55 / 100
601 ms84088 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 300005

vector<vector<pair<int,int>>> graph;
vector<pair<int,int>> edges;
vector<int> pathVis;
bool active(int i) {
	if (edges[i].f == -1)
		return false;
	return true;
}

void deactivate(int i) {
	edges[i].f = edges[i].s = -1;
}

int go_back = 0;
void dfs(int node, int parent) {
	pathVis[node] = true;
	for (auto u : graph[node]) {
		if (u.f == parent || !active(u.s))
			continue;

		if (pathVis[u.f]) {
			printf("%d ", u.f);
			go_back = u.f;
			deactivate(u.s);
			pathVis[node] = false;
		} else
			dfs(u.f, node);

		if (go_back) {
			if (go_back == node) {
				go_back = 0;
				deactivate(u.s);
				printf("\n");
				continue ;
			}
			printf("%d ", node);
			deactivate(u.s);
			pathVis[node] = false;
			return ;
		}
	}
	pathVis[node] = false;
}

int main() {
    int N, M, a, b;
    scanf("%d %d", &N, &M);

    graph = vector<vector<pair<int,int>>>(N+1, vector<pair<int,int>>());
    pathVis = vector<int>(N+1, false);
    for (int i = 0; i < M; i++) {
    	scanf("%d %d", &a, &b);
    	edges.push_back({a, b});
    	graph[a].push_back({b, edges.size()-1});
    	graph[b].push_back({a, edges.size()-1});
    }

    for (int i = 1; i <= N; i++)
    	dfs(i, i);
}

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

postmen.cpp: In function 'int main()':
postmen.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     scanf("%d %d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~
postmen.cpp:63:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |      scanf("%d %d", &a, &b);
      |      ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...