Submission #534117

# Submission time Handle Problem Language Result Execution time Memory
534117 2022-03-08T01:19:43 Z perchuts Pipes (CEOI15_pipes) C++17
30 / 100
1490 ms 65540 KB
#include <bits/stdc++.h>
#define maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define pb push_back
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf 2000000001
#define mod 1000000007 //998244353
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
int dp[2*maxn], lvl[2*maxn];
vector<ii>edges;

int getAdj(int u){
    return lower_bound(all(edges),make_pair(u,0)) - begin(edges);
}


int dfs(int u,int p){
    for(int i = getAdj(u);i<sz(edges)&&edges[i].first==u;++i){
        int v = edges[i].second;
        if(lvl[v]==0){
            lvl[v] = lvl[u]+1;
            dp[u] += dfs(v,u);
        }else if(lvl[v]>lvl[u]){
            dp[u]--;
        }else{
            dp[u]++;
        }
    }
    dp[u]--;
    if(dp[u]==0&&lvl[u]!=1)cout<<u<<" "<<p<<endl;
    return dp[u];
}

int main(){_
    int n,m;cin>>n>>m;
    edges.resize(2*m);
    for(int i=0;i<m;++i){
        int a,b;cin>>a>>b;
        edges[2*i] = {a,b};
        edges[2*i+1] = {b,a};
    }
    sort(all(edges));
    for(int i=0;i<2*m;++i){
        if(!lvl[edges[i].first]){
            lvl[edges[i].first] = 1;
            dfs(edges[i].first,edges[i].first);
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 844 KB Output is correct
2 Correct 5 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 10512 KB Output is correct
2 Correct 236 ms 9960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 382 ms 17456 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 577 ms 26528 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 735 ms 35900 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1266 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1490 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 41 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -