Submission #698728

# Submission time Handle Problem Language Result Execution time Memory
698728 2023-02-14T08:48:49 Z Quan2003 Pipes (CEOI15_pipes) C++17
20 / 100
1130 ms 12924 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 1;
long long n,m,dsz;
vector<int>adj[N + 1];
int a[N + 1],low[N + 1]; 
struct DSU{
    int fa[N + 1];
    void init(int n){
         for(int i = 1; i <= n; i++) fa[i] = i; 
    }
    int find(int u){
        if(u == fa[u]) return u;
        return fa[u] = find(fa[u]);
    }
    bool unite(int u,int v){
        u = find(u); v = find(v);
        if(u == v) return 0;
        fa[v] = u;
        return 1;
    } 
} dsu_cc, dsu_2ecc; 
void dfs(int u,int p){
    a[u] = low[u] = ++dsz;
    for(int i = 0; i < adj[u].size(); i++){
        int v = adj[u][i]; 
        if(v == p) continue;
        if(!a[v]){
            dfs(v,u);
            low[u] = min(low[u] , low[v]);
            if(low[v] > a[u]) printf("%d %d\n",u,v); 
        }
        else low[u] = min(a[v] , low[u]);
    }
}
int main(){
    scanf("%d%d",&n,&m); 
    dsu_cc.init(n); 
    dsu_2ecc.init(n); 
    for(int i = 1; i <= m; i++){
         int a,b; scanf("%d%d",&a,&b); 
         if(dsu_cc.unite(a,b) or dsu_2ecc.unite(a,b)){
               adj[a].push_back(b); 
               adj[b].push_back(a); 
         }
    }    
    for(int i = 1; i <= n; i++) if(!a[i]) dfs(i,0);
}

Compilation message

pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i = 0; i < adj[u].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:38:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   38 |     scanf("%d%d",&n,&m);
      |            ~^    ~~
      |             |    |
      |             int* long long int*
      |            %lld
pipes.cpp:38:15: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   38 |     scanf("%d%d",&n,&m);
      |              ~^     ~~
      |               |     |
      |               int*  long long int*
      |              %lld
pipes.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
pipes.cpp:42:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |          int a,b; scanf("%d%d",&a,&b);
      |                   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3028 KB Output is correct
2 Incorrect 5 ms 2936 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 2936 KB Output is correct
2 Incorrect 97 ms 2804 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 158 ms 3624 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 276 ms 5064 KB Output is correct
2 Correct 235 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 353 ms 9892 KB Output is correct
2 Incorrect 317 ms 7036 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 550 ms 10880 KB Output is correct
2 Incorrect 552 ms 8648 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 732 ms 12924 KB Output is correct
2 Incorrect 694 ms 8904 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 881 ms 12924 KB Output is correct
2 Incorrect 848 ms 8836 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1130 ms 12424 KB Output is correct
2 Correct 1052 ms 10056 KB Output is correct