Submission #941026

# Submission time Handle Problem Language Result Execution time Memory
941026 2024-03-08T05:19:52 Z KaleemRazaSyed Senior Postmen (BOI14_postmen) C++17
0 / 100
6 ms 12636 KB
#include<iostream>
#include<vector>

using namespace std;

const int N = 5e5+5;
struct edge
{
  int u, v;
  bool vis;
  int other(int x)
  {
    return u + v - x;
  }
};
vector<int> G[N];
vector<edge> e;
vector<int> p;

void dfs(int v)
{
  p.push_back(v);
  while(G[v].size())
    {
      int i = G[v].back();
      G[v].pop_back();
      if(e[i].vis)
	continue;
      e[i].vis = true;
      dfs(e[i].other(v));
    }
}

bool seen[N];

int main()
{
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < m; i ++)
    {
      int u, v;
      cin >> u >> v;
      G[u].push_back(i);
      G[v].push_back(i);
      e.push_back(edge{u, v, false});
    }
  for(int i = 1; i <= n; i ++)
    {
      if(G[i].size())
	dfs(i);
    }
 
  vector<int> ans;
  for(int i = 0; i < p.size(); i++)
    {
      if(!seen[p[i]])
	ans.push_back(p[i]);
      else
	{
	  cout << p[i];
	  while(ans.back() != p[i])
	    {
	      cout << ' ' << ans.back();
	      seen[ans.back()] = false;
	      ans.pop_back();
	    }
	  cout << '\n';
	}
      seen[p[i]] = true;
    }
  return 0;
}

Compilation message

postmen.cpp: In function 'int main()':
postmen.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int i = 0; i < p.size(); i++)
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12380 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Correct 4 ms 12380 KB Output is correct
4 Correct 6 ms 12636 KB Output is correct
5 Incorrect 4 ms 12380 KB Some edges were not used
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12380 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Correct 3 ms 12380 KB Output is correct
4 Correct 4 ms 12636 KB Output is correct
5 Incorrect 3 ms 12380 KB Some edges were not used
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12380 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Correct 3 ms 12380 KB Output is correct
4 Correct 5 ms 12632 KB Output is correct
5 Incorrect 3 ms 12380 KB Some edges were not used
6 Halted 0 ms 0 KB -