# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
669292 |
2022-12-06T08:12:52 Z |
manizare |
Pipes (CEOI15_pipes) |
C++11 |
|
998 ms |
18896 KB |
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std ;
const int maxn = 2e5+100 , maxq =5002 , inf = 2e17 + 100 , mod = 1e9 + 7 ;
vector <pair <int , int > >G[maxn] ;
int par[maxn] , par2[maxn] , p[maxn] , dp[maxn] , mark[maxn] , dis[maxn] , j[maxn];
int find(int v){
if(par[v] == v)return v;
return par[v] = find(par[v]);
}
int find2(int v){
if(par2[v] == v)return v;
return par2[v] = find2(par2[v]) ;
}
void dfs(int v){
mark[v] = 1;
for(int i = 0 ; i < G[v].size() ; i++){
int u = G[v][i].first , o = G[v][i].second; ;
if(mark[u] == 1){
if(j[o] == 0 && dis[u] < (dis[v])){
dp[v] ++ ;
dp[u]--;
}
continue ;
}
dis[u] = dis[v] + 1;
p[u] = v;
j[o] = 1;
dfs(u);
dp[v] += dp[u] ;
}
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
int n , m ;
cin >> n >> m ;
for(int i= 1 ; i <= n ; i++){
par[i] = i ;
par2[i] = i ;
}
int c = 1;
for(int i =1 ; i <= m ; i++){
int v , u ;
cin >> v >> u ;
int v1 = find(v) , u1 = find(u);
if(v1 != u1){
G[v].pb({u , c}) ;
G[u].pb({v , c});c++;
par[v1] = u1 ;
}else if(find2(v) != find2(u)){
par2[find2(v)] = find2(u);
G[v].pb({u,c}) ;
G[u].pb({v,c});c++;
}
}
for(int i = 1; i <= n ; i++){
if(mark[i] == 0)dfs(i);
}
for(int i = 1; i <= n ; i++){
if(dp[i] == 0 && p[i] != 0){
cout << i << " " << p[i] << "\n";
}
}
}
Compilation message
pipes.cpp:5:52: warning: overflow in conversion from 'double' to 'int' changes value from '2.000000000000001e+17' to '2147483647' [-Woverflow]
5 | const int maxn = 2e5+100 , maxq =5002 , inf = 2e17 + 100 , mod = 1e9 + 7 ;
| ~~~~~^~~~~
pipes.cpp: In function 'void dfs(int)':
pipes.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int i = 0 ; i < G[v].size() ; i++){
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5588 KB |
Output is correct |
2 |
Correct |
6 ms |
5460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
5452 KB |
Output is correct |
2 |
Correct |
83 ms |
5276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
6364 KB |
Output is correct |
2 |
Correct |
203 ms |
14996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
234 ms |
8300 KB |
Output is correct |
2 |
Correct |
218 ms |
7816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
345 ms |
14728 KB |
Output is correct |
2 |
Correct |
351 ms |
11852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
519 ms |
16264 KB |
Output is correct |
2 |
Correct |
480 ms |
12700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
866 ms |
18896 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
907 ms |
18824 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
998 ms |
18088 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |