Submission #698778

# Submission time Handle Problem Language Result Execution time Memory
698778 2023-02-14T09:44:58 Z Quan2003 Pipes (CEOI15_pipes) C++17
100 / 100
1096 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;
    bool chk = 0;
    for(int i = 0; i < adj[u].size(); i++){
        int v = adj[u][i]; 
        if(v != p or chk){
          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]);
       } 
       else chk = 1; 
    }
    //cout<<low[u]<<' '<<a[u]<<' '<<u<<endl;
    if(low[u] == a[u] and p) printf("%d %d\n",u,p); 
}
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:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i < adj[u].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:43:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   43 |     scanf("%d%d",&n,&m);
      |            ~^    ~~
      |             |    |
      |             int* long long int*
      |            %lld
pipes.cpp:43:15: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   43 |     scanf("%d%d",&n,&m);
      |              ~^     ~~
      |               |     |
      |               int*  long long int*
      |              %lld
pipes.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
pipes.cpp:47:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |          int a,b; scanf("%d%d",&a,&b);
      |                   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3100 KB Output is correct
2 Correct 5 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 2936 KB Output is correct
2 Correct 101 ms 2804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 3620 KB Output is correct
2 Correct 185 ms 3236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 293 ms 5068 KB Output is correct
2 Correct 232 ms 4760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 388 ms 9844 KB Output is correct
2 Correct 320 ms 7020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 565 ms 10972 KB Output is correct
2 Correct 553 ms 8420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 803 ms 12920 KB Output is correct
2 Correct 701 ms 8844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 920 ms 12924 KB Output is correct
2 Correct 967 ms 8852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1082 ms 12416 KB Output is correct
2 Correct 1096 ms 10096 KB Output is correct