# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
448689 |
2021-07-31T17:05:57 Z |
S2speed |
Pipes (CEOI15_pipes) |
C++17 |
|
1375 ms |
9496 KB |
#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;
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
pipes.cpp: In function 'int main()':
pipes.cpp:80:8: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
80 | cur <<= 1; if(cur >= md) cur -= md;
| ~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2944 KB |
Output is correct |
2 |
Correct |
5 ms |
3020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
3788 KB |
Output is correct |
2 |
Correct |
117 ms |
4036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
200 ms |
4160 KB |
Output is correct |
2 |
Correct |
229 ms |
4156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
349 ms |
4940 KB |
Output is correct |
2 |
Correct |
305 ms |
5060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
463 ms |
6804 KB |
Output is correct |
2 |
Correct |
380 ms |
6820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
703 ms |
8376 KB |
Output is correct |
2 |
Correct |
706 ms |
7936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
966 ms |
9484 KB |
Output is correct |
2 |
Correct |
860 ms |
9360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1126 ms |
8700 KB |
Output is correct |
2 |
Correct |
1117 ms |
9496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1365 ms |
9168 KB |
Output is correct |
2 |
Correct |
1375 ms |
8508 KB |
Output is correct |