답안 #197810

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197810 2020-01-23T11:14:55 Z dndhk 어르신 집배원 (BOI14_postmen) C++14
55 / 100
500 ms 34236 KB
#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;
}

Compilation message

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);
             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 29 ms 12032 KB Output is correct
3 Correct 13 ms 12032 KB Output is correct
4 Correct 17 ms 12160 KB Output is correct
5 Correct 11 ms 12160 KB Output is correct
6 Correct 14 ms 12160 KB Output is correct
7 Correct 18 ms 12544 KB Output is correct
8 Correct 13 ms 12160 KB Output is correct
9 Correct 49 ms 14548 KB Output is correct
10 Correct 14 ms 12328 KB Output is correct
11 Correct 12 ms 12288 KB Output is correct
12 Correct 55 ms 14840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12084 KB Output is correct
2 Correct 14 ms 12032 KB Output is correct
3 Correct 11 ms 12032 KB Output is correct
4 Correct 14 ms 12288 KB Output is correct
5 Correct 13 ms 12160 KB Output is correct
6 Correct 14 ms 12160 KB Output is correct
7 Correct 20 ms 12672 KB Output is correct
8 Correct 15 ms 12160 KB Output is correct
9 Correct 50 ms 14424 KB Output is correct
10 Correct 14 ms 12160 KB Output is correct
11 Correct 14 ms 12160 KB Output is correct
12 Correct 57 ms 14840 KB Output is correct
13 Correct 91 ms 16504 KB Output is correct
14 Correct 97 ms 15696 KB Output is correct
15 Correct 81 ms 15340 KB Output is correct
16 Correct 88 ms 16476 KB Output is correct
17 Correct 95 ms 15608 KB Output is correct
18 Correct 85 ms 15864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 12 ms 12032 KB Output is correct
4 Correct 12 ms 12136 KB Output is correct
5 Correct 12 ms 12164 KB Output is correct
6 Correct 13 ms 12160 KB Output is correct
7 Correct 25 ms 12544 KB Output is correct
8 Correct 12 ms 12160 KB Output is correct
9 Correct 48 ms 14456 KB Output is correct
10 Correct 14 ms 12160 KB Output is correct
11 Correct 13 ms 12160 KB Output is correct
12 Correct 60 ms 14880 KB Output is correct
13 Correct 96 ms 16504 KB Output is correct
14 Correct 95 ms 15736 KB Output is correct
15 Correct 88 ms 15308 KB Output is correct
16 Correct 89 ms 16500 KB Output is correct
17 Correct 103 ms 15612 KB Output is correct
18 Correct 85 ms 15892 KB Output is correct
19 Execution timed out 531 ms 34236 KB Time limit exceeded
20 Halted 0 ms 0 KB -