Submission #448694

# Submission time Handle Problem Language Result Execution time Memory
448694 2021-07-31T17:51:33 Z S2speed Pipes (CEOI15_pipes) C++17
0 / 100
1371 ms 8604 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;
}

int ds[maxn] , jad[maxn][17];

int dsu(int v){
	return (ds[v] == v ? v : ds[v] = dsu(ds[v]));
}

bool merge(int v , int u){
	v = dsu(v); u = dsu(u);
	ds[u] = v;
	return (v != u);
}

int f[maxn] , par[maxn];
vector<int> adj[maxn];
bitset<maxn> mark;

void fDFS(int 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);

	int n , m , cur;
	cin>>n>>m;
	iota(ds , ds + n , 0);
	for(int i = 0 ; i < m ; i++){
		int 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(int i = 0 ; i < n ; i++){
		if(mark[i]) continue;
		par[i] = -1;
		fDFS(i);
	}
	for(int 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 Incorrect 2 ms 2636 KB Mismatched edge
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 3020 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 124 ms 3220 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 211 ms 3572 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 342 ms 4352 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 435 ms 6580 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 688 ms 7468 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 911 ms 8588 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1122 ms 8284 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1371 ms 8604 KB Wrong number of edges
2 Halted 0 ms 0 KB -