Submission #413925

# Submission time Handle Problem Language Result Execution time Memory
413925 2021-05-29T17:28:32 Z Blagojce Senior Postmen (BOI14_postmen) C++11
55 / 100
500 ms 48636 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi  = 3.14159265359;
 
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 5*1e5+5;
 
int n, m;
vector<int> g[mxn];
int deg[mxn];
bool used[mxn];
int l[mxn], r[mxn];
 
vector<int> cycle;
/*
void euler(int u, int dep){
	cout<<dep<<endl;
	
	while(deg[u] > 0){
		cout<<"a";
		int e = g[u][deg[u]-1];
		cout<<"b";
		int v = l[e];
		cout<<"v";
		if(v == u) v = r[e];
		--deg[u];
		cout<<"g";
		
		cout<<e<<endl;
		if(used[e]) continue;
		used[e] = true;
		cout<<"BEFORE"<<endl;
		euler(v, dep+1);
	}
	
	cycle.pb(u);
}
*/
stack<int> S;
void eul(){
	S.push(0);
	while(!S.empty()){
		int u = S.top();
		if(deg[u] > 0){
			int e = g[u][deg[u]-1];
			int v = l[e];
			if(v == u) v = r[e];
			--deg[u];
			if(used[e]) continue;
			used[e] = true;
			S.push(v);
		}
		else{
			cycle.pb(u);
			S.pop();
		}
	}
}

bool vis[mxn];
 
int main(){
	//freopen("untitled.in", "r",stdin);
	scanf("%d %d", &n, &m);
	fr(i, 0, m){
		scanf("%d %d", &l[i], &r[i]);
		--l[i], --r[i];
		++deg[l[i]];
		++deg[r[i]];
		g[l[i]].pb(i);
		g[r[i]].pb(i);
	}
	
	//euler(0, 0);
	eul();
	stack<int> S;
	for(auto u : cycle){
		if(vis[u]){
			while(1){
				int x = S.top();
				printf("%d ", x+1);
				S.pop();
				vis[x] = false;
				if(x == u){
					printf("\n");
					break;
				}
			}
		}
		vis[u] = true;
		S.push(u);
	}
}

Compilation message

postmen.cpp: In function 'int main()':
postmen.cpp:79:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
postmen.cpp:81:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |   scanf("%d %d", &l[i], &r[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11980 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 9 ms 12052 KB Output is correct
4 Correct 9 ms 12236 KB Output is correct
5 Correct 10 ms 12048 KB Output is correct
6 Correct 11 ms 12196 KB Output is correct
7 Correct 15 ms 12712 KB Output is correct
8 Correct 9 ms 12184 KB Output is correct
9 Correct 55 ms 15804 KB Output is correct
10 Correct 9 ms 12204 KB Output is correct
11 Correct 12 ms 12164 KB Output is correct
12 Correct 67 ms 16288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12048 KB Output is correct
2 Correct 9 ms 12032 KB Output is correct
3 Correct 7 ms 11980 KB Output is correct
4 Correct 9 ms 12224 KB Output is correct
5 Correct 8 ms 12108 KB Output is correct
6 Correct 11 ms 12272 KB Output is correct
7 Correct 18 ms 12764 KB Output is correct
8 Correct 11 ms 12104 KB Output is correct
9 Correct 64 ms 15900 KB Output is correct
10 Correct 12 ms 12236 KB Output is correct
11 Correct 9 ms 12192 KB Output is correct
12 Correct 71 ms 16360 KB Output is correct
13 Correct 83 ms 19192 KB Output is correct
14 Correct 76 ms 18000 KB Output is correct
15 Correct 67 ms 17892 KB Output is correct
16 Correct 74 ms 19228 KB Output is correct
17 Correct 74 ms 17756 KB Output is correct
18 Correct 85 ms 18192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11980 KB Output is correct
2 Correct 9 ms 12024 KB Output is correct
3 Correct 8 ms 11980 KB Output is correct
4 Correct 10 ms 12236 KB Output is correct
5 Correct 9 ms 12060 KB Output is correct
6 Correct 10 ms 12192 KB Output is correct
7 Correct 14 ms 12748 KB Output is correct
8 Correct 9 ms 12108 KB Output is correct
9 Correct 58 ms 15988 KB Output is correct
10 Correct 10 ms 12192 KB Output is correct
11 Correct 10 ms 12200 KB Output is correct
12 Correct 53 ms 16252 KB Output is correct
13 Correct 74 ms 19180 KB Output is correct
14 Correct 72 ms 17960 KB Output is correct
15 Correct 78 ms 17848 KB Output is correct
16 Correct 85 ms 19136 KB Output is correct
17 Correct 95 ms 17864 KB Output is correct
18 Correct 74 ms 18108 KB Output is correct
19 Execution timed out 522 ms 48636 KB Time limit exceeded
20 Halted 0 ms 0 KB -