Submission #252410

# Submission time Handle Problem Language Result Execution time Memory
252410 2020-07-25T13:39:24 Z shayan_p Duathlon (APIO18_duathlon) C++14
0 / 100
168 ms 34424 KB
// And you curse yourself for things you never done

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 3e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;

vector<int> v[maxn], g[maxn], vec;
int up[maxn], h[maxn], val[maxn], n;
bool mark[maxn];
int C;

void add_edge(int a, int b){
    g[a].PB(b);
    g[b].PB(a);
}
void prep(int u){    
    mark[u] = 1;
    up[u] = h[u];
    for(int y : v[u]){
	if(!mark[y]){
	    int SZ = sz(vec);
	    
	    h[y] = h[u] + 1;
	    prep(y);
	    up[u] = min(up[u], up[y]);
	    
	    if(up[y] == h[u]){
		while(sz(vec) > SZ){
		    add_edge(vec.back(), C);
		    vec.pop_back();
		}
		add_edge(u, C);
		val[C] = sz(g[C]) - 1;
		C++;
	    }
	}
	else{
	    up[u] = min(up[u], h[y]);	    
	}	    
    }    
    vec.PB(u);
}

ll ans;
int SZ[maxn];

void dfs(int u, int par = -1){
    SZ[u] = (u < n);
    ll num = 0;
    for(int y : g[u])
	if(y != par)
	    dfs(y, u), SZ[u]+= SZ[y], num+= 1ll * SZ[y] * (SZ[y]-1);
    num+= 1ll * (n-SZ[u]) * (n-SZ[u]-1);
    ans+= 1ll * val[u] * (1ll * n * (n-1) - num);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();

    int m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
	int a, b;
	cin >> a >> b;
	--a, --b;
	v[a].PB(b);
	v[b].PB(a);
    }
    C = n;
    prep(0);
    ans = -1ll * n * (n-1);
    dfs(0);    
    return cout << ans << endl, 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 14464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 14464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 112 ms 32188 KB Output is correct
2 Correct 81 ms 32112 KB Output is correct
3 Incorrect 63 ms 25460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14592 KB Output is correct
2 Correct 8 ms 14592 KB Output is correct
3 Correct 9 ms 14592 KB Output is correct
4 Correct 12 ms 14720 KB Output is correct
5 Correct 8 ms 14592 KB Output is correct
6 Correct 8 ms 14592 KB Output is correct
7 Correct 8 ms 14592 KB Output is correct
8 Correct 8 ms 14592 KB Output is correct
9 Correct 8 ms 14592 KB Output is correct
10 Incorrect 8 ms 14464 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 134 ms 26232 KB Output is correct
2 Correct 131 ms 26104 KB Output is correct
3 Correct 120 ms 26104 KB Output is correct
4 Correct 100 ms 26104 KB Output is correct
5 Correct 109 ms 26104 KB Output is correct
6 Correct 111 ms 34424 KB Output is correct
7 Correct 113 ms 31608 KB Output is correct
8 Correct 113 ms 30200 KB Output is correct
9 Correct 120 ms 28792 KB Output is correct
10 Incorrect 75 ms 23032 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14592 KB Output is correct
2 Correct 8 ms 14592 KB Output is correct
3 Correct 8 ms 14592 KB Output is correct
4 Correct 8 ms 14592 KB Output is correct
5 Correct 9 ms 14592 KB Output is correct
6 Correct 9 ms 14592 KB Output is correct
7 Correct 9 ms 14592 KB Output is correct
8 Correct 10 ms 14592 KB Output is correct
9 Correct 9 ms 14592 KB Output is correct
10 Correct 8 ms 14592 KB Output is correct
11 Correct 8 ms 14592 KB Output is correct
12 Correct 9 ms 14592 KB Output is correct
13 Correct 9 ms 14592 KB Output is correct
14 Correct 8 ms 14592 KB Output is correct
15 Correct 9 ms 14592 KB Output is correct
16 Incorrect 8 ms 14464 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 98 ms 26104 KB Output is correct
2 Correct 102 ms 25976 KB Output is correct
3 Correct 105 ms 25336 KB Output is correct
4 Correct 113 ms 24440 KB Output is correct
5 Correct 101 ms 23672 KB Output is correct
6 Correct 101 ms 23288 KB Output is correct
7 Correct 91 ms 23160 KB Output is correct
8 Correct 89 ms 22904 KB Output is correct
9 Correct 101 ms 22904 KB Output is correct
10 Correct 99 ms 22848 KB Output is correct
11 Correct 85 ms 22776 KB Output is correct
12 Correct 84 ms 22904 KB Output is correct
13 Correct 81 ms 22904 KB Output is correct
14 Correct 101 ms 25068 KB Output is correct
15 Correct 123 ms 31128 KB Output is correct
16 Correct 141 ms 29176 KB Output is correct
17 Correct 147 ms 29816 KB Output is correct
18 Correct 168 ms 28024 KB Output is correct
19 Incorrect 125 ms 24184 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 14464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 14464 KB Output isn't correct
2 Halted 0 ms 0 KB -