Submission #451435

# Submission time Handle Problem Language Result Execution time Memory
451435 2021-08-03T07:53:47 Z ak2006 Pipes (CEOI15_pipes) C++14
100 / 100
1411 ms 14776 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
    fast;
}
const int maxN = 1e5 + 5;
int n,m,TIMER;
vvi adj(maxN);
vi low(maxN),in(maxN),p1(maxN,-1),p2(maxN,-1);
struct DSU
{
    int p[maxN];
    DSU(){
        for (int i = 0;i<=maxN;i++)p[i] = -1;
    }
    int Find(int u)
    {   
        if (p[u] < 0)return u;
        return p[u] = Find(p[u]);
    }
    int Merge(int u,int v)
    {
        u = Find(u),v = Find(v);
        if (u == v)return false;
        if (p[v] > p[u])swap(u,v);
        p[u] += p[v];
        p[v] = u;
        return true;
    }
}v1,v2;
void dfs(int u,int p)
{   
    in[u] = low[u] = ++TIMER;
    bool is = false;
    for (int v:adj[u]){
        if (v != p or is){
            if (in[v])
                low[u] = min(low[u],in[v]);
            else 
                dfs(v,u),low[u] = min(low[u],low[v]);
        }
        else is = true;
    }
    if (low[u] == in[u] && p!=-1)cout<<u<<" "<<p<<'\n';
}
int main()

{
    setIO();
    cin>>n>>m;
    int cnt = 0;
    for (int i = 1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        if (v1.Merge(u,v) or v2.Merge(u,v))
            adj[u].pb(v),adj[v].pb(u),cnt++;
        assert(cnt <= 2 * n - 2);
    }
    for (int i = 1;i<=n;i++)if (!in[i])dfs(i,-1);
    return 0;
}

Compilation message

pipes.cpp: In function 'void __static_initialization_and_destruction_0(int, int)':
pipes.cpp:28:41: warning: iteration 100005 invokes undefined behavior [-Waggressive-loop-optimizations]
   28 |         for (int i = 0;i<=maxN;i++)p[i] = -1;
      |                                    ~~~~~^~~~
pipes.cpp:28:25: note: within this loop
   28 |         for (int i = 0;i<=maxN;i++)p[i] = -1;
      |                        ~^~~~~~
pipes.cpp:28:41: warning: iteration 100005 invokes undefined behavior [-Waggressive-loop-optimizations]
   28 |         for (int i = 0;i<=maxN;i++)p[i] = -1;
      |                                    ~~~~~^~~~
pipes.cpp:28:25: note: within this loop
   28 |         for (int i = 0;i<=maxN;i++)p[i] = -1;
      |                        ~^~~~~~
In constructor 'DSU::DSU()',
    inlined from 'void __static_initialization_and_destruction_0(int, int)' at pipes.cpp:44:2,
    inlined from '(static initializers for pipes.cpp)' at pipes.cpp:75:1:
pipes.cpp:28:41: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [400020, 400023] is out of the bounds [0, 400020] of object 'v1' with type 'DSU' [-Warray-bounds]
   28 |         for (int i = 0;i<=maxN;i++)p[i] = -1;
      |                                    ~~~~~^~~~
pipes.cpp: In function '(static initializers for pipes.cpp)':
pipes.cpp:44:2: note: 'v1' declared here
   44 | }v1,v2;
      |  ^~
In constructor 'DSU::DSU()',
    inlined from 'void __static_initialization_and_destruction_0(int, int)' at pipes.cpp:44:5,
    inlined from '(static initializers for pipes.cpp)' at pipes.cpp:75:1:
pipes.cpp:28:41: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [400020, 400023] is out of the bounds [0, 400020] of object 'v2' with type 'DSU' [-Warray-bounds]
   28 |         for (int i = 0;i<=maxN;i++)p[i] = -1;
      |                                    ~~~~~^~~~
pipes.cpp: In function '(static initializers for pipes.cpp)':
pipes.cpp:44:5: note: 'v2' declared here
   44 | }v1,v2;
      |     ^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5452 KB Output is correct
2 Correct 7 ms 5196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 5304 KB Output is correct
2 Correct 113 ms 5168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 5912 KB Output is correct
2 Correct 248 ms 5392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 334 ms 7252 KB Output is correct
2 Correct 296 ms 6852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 471 ms 11860 KB Output is correct
2 Correct 398 ms 8344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 704 ms 12812 KB Output is correct
2 Correct 732 ms 9960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 911 ms 14652 KB Output is correct
2 Correct 872 ms 9772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1244 ms 14776 KB Output is correct
2 Correct 1103 ms 9928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1411 ms 14184 KB Output is correct
2 Correct 1360 ms 11496 KB Output is correct