Submission #115966

#TimeUsernameProblemLanguageResultExecution timeMemory
115966Mahdi_JfriSenior Postmen (BOI14_postmen)C++14
100 / 100
342 ms43480 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int maxn = 1e6 + 20; vector<int> path; int from[maxn] , to[maxn] , last[maxn] , head[maxn] , id; bool visited[maxn]; void add_edge(int v , int u) { from[id] = v , to[id] = u , last[id] = head[v] , head[v] = id , id++; from[id] = u , to[id] = v , last[id] = head[u] , head[u] = id , id++; } void dfs(int v) { while(head[v] != -1) { int e = head[v] , u = to[e]; head[v] = last[e]; if(visited[e / 2]) continue; visited[e / 2] = 1; dfs(u); } path.pb(v); } int main() { memset(head , -1 , sizeof head); int n , m; scanf("%d%d", &n, &m); for(int i = 0; i < m; i++) { int a , b; scanf("%d%d", &a, &b); a-- , b--; add_edge(a , b); } dfs(0); vector<int> tmp; memset(visited , 0 , sizeof visited); for(auto v : path) { if(visited[v]) { while(tmp.back() != v) { printf("%d ", tmp.back() + 1); visited[tmp.back()] = 0; tmp.pop_back(); } tmp.pop_back(); printf("%d\n", v + 1); } tmp.pb(v); visited[v] = 1; } }

Compilation message (stderr)

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