Submission #28715

# Submission time Handle Problem Language Result Execution time Memory
28715 2017-07-16T08:59:50 Z rondojim Pipes (CEOI15_pipes) C++14
0 / 100
2406 ms 65536 KB
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

const int MAXN = 8e4 + 5;
typedef pair<int, int> edge;

vector<int> adj[MAXN];
bool vis[MAXN];
int num[MAXN], low[MAXN], pos = 1, N, M;
vector<edge> bridges;

void dfs(int u, int p){
  vis[u] = true;
  num[u] = pos++;
  low[u] = num[u];
  for(int v : adj[u]){
    if(vis[v] == false){
      dfs(v, u);
      low[u] = min(low[u], low[v]);
      if(low[v] > num[u]) bridges.push_back((edge){min(v,u),max(v,u)});
    }
    else if(v != p) low[u] = min(low[u], num[v]);
  }
}

int main(){
  scanf("%d %d", &N, &M);
  int a, b;
  set<edge> S;
  while(M--){
    scanf("%d %d", &a, &b);
    int aa = min(a, b), bb = max(a, b);
    edge p = {aa, bb};
    if(S.find(p) != S.end()) continue;
    S.insert(p);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for(int i=1; i<=N; ++i) if(!vis[i]) dfs(i, -1);
  for(int i=0; i<bridges.size(); ++i) printf("%d %d\n", bridges[i].first, bridges[i].second);
  return 0;
}
    
  

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:44:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<bridges.size(); ++i) printf("%d %d\n", bridges[i].first, bridges[i].second);
                ~^~~~~~~~~~~~~~~
pipes.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &N, &M);
   ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &a, &b);
     ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2176 KB Output is correct
2 Incorrect 3 ms 2176 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3328 KB Output is correct
2 Incorrect 11 ms 3072 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Runtime error 1248 ms 36888 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2406 ms 60332 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2177 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2379 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2396 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 4224 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 4196 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 4064 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -