Submission #227653

#TimeUsernameProblemLanguageResultExecution timeMemory
227653arman_ferdousSenior Postmen (BOI14_postmen)C++17
38 / 100
1094 ms11384 KiB
/* Author : arman_ferdous 
 * Date   : 28 Apr 2020 14:31:14
 * TAG    : Noob Problem 
 */

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ii = pair<int,int>;

const int N = 5e5+10;
const int M = 1e6+10;

int n, m;
int eptr, to[M], pre[M], last[M];

void add_edge(int u, int v) {
  to[eptr] = v;
  pre[eptr] = last[u];
  last[u] = eptr;
  eptr++;
}

int vis[M];
stack<int> st;
void tour(int u) {
  for(int i = last[u]; i + 1; i = pre[i]) {
    last[u] = pre[i];
    if(vis[i]) continue;
    vis[i] = 1;
    vis[i ^ 1] = 1;
    tour(to[i]);
  }
  st.push(u);
}

stack<int> soln;

int main() { 
  memset(last, -1, sizeof last);
  scanf("%d %d", &n, &m);
  for(int i = 0; i < m; i++) {
    int u, v; scanf("%d %d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }
  tour(1);
  for(int i = 1; i <= n; i++) vis[i] = 0;
  while(!st.empty()) {
    int u = st.top(); st.pop();
    if(vis[u]) {
      printf("%d ", u);
      while(!soln.empty()) {
        int v = soln.top(); soln.pop();
        if(v == u) break;
        printf("%d ", v);
        vis[v] = 0;
      }
      puts("");
    } 
    vis[u] = 1;
    soln.push(u);
  }
  return 0;
}

Compilation message (stderr)

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