Submission #448695

#TimeUsernameProblemLanguageResultExecution timeMemory
448695S2speedPipes (CEOI15_pipes)C++17
100 / 100
1476 ms9288 KiB
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize ("Ofast") #define all(x) x.begin() , x.end() #define sze(x) (ll)(x.size()) #define mp(x , y) make_pair(x , y) #define wall cout<<"--------------------------------------"<<endl typedef long long int ll; typedef pair<ll , ll> pll; typedef pair<int , int> pii; typedef long double db; typedef pair<pll , ll> plll; typedef pair<pii , int> piii; typedef pair<pll , pll> pllll; const ll maxn = 1e5 + 16 , md = 2000000357 , inf = 2e16; ll gcd(ll a , ll b){ if(a < b) swap(a , b); if(b == 0) return a; return gcd(b , a % b); } ll tav(ll n , ll k){ ll res = 1; while(k > 0){ if(k & 1){ res *= n; res %= md; } n *= n; n %= md; k >>= 1; } return res; } ll ds[maxn]; ll dsu(ll v){ return (ds[v] == v ? v : ds[v] = dsu(ds[v])); } bool merge(ll v , ll u){ v = dsu(v); u = dsu(u); ds[u] = v; return (v != u); } ll f[maxn] , par[maxn]; vector<ll> adj[maxn]; bitset<maxn> mark; int jad[maxn][17]; void fDFS(ll r){ mark[r] = true; for(auto i : adj[r]){ if(i == par[r]) continue; par[i] = r; fDFS(i); f[r] += f[i]; } f[r] %= md; if(f[r] < 0) f[r] += md; return; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n , m , cur; cin>>n>>m; iota(ds , ds + n , 0); for(ll i = 0 ; i < m ; i++){ ll v , u; cin>>v>>u; v--; u--; if(merge(v , u)){ adj[v].push_back(u); adj[u].push_back(v); } else { f[v] += cur; f[u] -= cur; cur <<= 1; if(cur >= md) cur -= md; } } for(ll i = 0 ; i < n ; i++){ if(mark[i]) continue; par[i] = -1; fDFS(i); } for(ll i = 0 ; i < n ; i++){ if(f[i] != 0 || par[i] == -1) continue; cout<<i + 1<<' '<<par[i] + 1<<'\n'; } return 0; }

Compilation message (stderr)

pipes.cpp: In function 'int main()':
pipes.cpp:81:8: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
   81 |    cur <<= 1; if(cur >= md) cur -= md;
      |    ~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...