답안 #232048

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232048 2020-05-15T20:04:21 Z AQT 철인 이종 경기 (APIO18_duathlon) C++14
10 / 100
151 ms 52620 KB
// Problem : APIO '18 P3 - Duathlon
// Contest : DMOJ
// URL : https://dmoj.ca/problem/apio18p3
// Memory Limit : 1 MB
// Time Limit : 600 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int N, M;
vector<int> graph[100005], cgraph[200005];
vector<pair<int, int>> stk;
vector<vector<pair<int, int>>> cmp;
int par[200005], dfn[100005], low[100005], t;
long long sz[100005], dp[100005];
long long ans;

void dfs1(int n){
	low[n] = dfn[n] = ++t;
	int c = 0;
	for(int e : graph[n]){
		if(e == par[n]){
			continue;
		}
		if(!dfn[e]){
			c++;
			par[e] = n;
			stk.emplace_back(n, e);					
			dfs1(e);
			low[n] = min(low[n], low[e]);
			if((!par[n] && c >= 2) || (par[n] && low[n] == dfn[n])){
				pair<int, int> edg = {0, 0};
				vector<pair<int, int>> tmp;
				do{
					edg = stk.back();
					stk.pop_back();
					tmp.push_back(edg);
				}
				while(edg != make_pair(n, e));
				cmp.push_back(tmp);
			}
		}
		else if(dfn[e] < dfn[n]){
			low[n] = min(dfn[e], low[n]);
			stk.emplace_back(n, e);		
		}
	}
}

void dfs2(int n){
	sz[n] = n <= N;
	long long dsum = 0, cld = 0;
	for(int e : cgraph[n]){
		if(e != par[n]){
			cld++;
			par[e] = n;
			dfs2(e);
			if(n <= N){
				ans += dp[e] * sz[n];
				ans += sz[e] * (sz[n] - 1 + dsum);
				dsum += dp[e];
				dp[n] += dp[e] + sz[e];
				sz[n] += sz[e];
			}
			else{
				ans += dp[e] * sz[n];
				ans += sz[e] * dsum;
				dsum += dp[e];
				dp[n] += dp[e] + sz[e] * sz[n];				
				sz[n] += sz[e];
				//cout << n << " " << sz[e] << " " << sz[n] << " " << dp[e] << "\n";
			}
		}
	}
	//cout << n << " " << sz[n] << " " << dp[n] << "\n";
	/*
	if(n > N){
		dp[n] += cld * (cld-1) / 2;
	}
	*/
}

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> M;
	for(int i = 1; i<=M; i++){
		int a, b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	int C = N;
	for(int i = 1; i<=N; i++){
		if(!dfn[i]){
			dfs1(i);
			if(stk.size()){
				cmp.push_back(stk);
				stk.clear();
			}
			for(auto v : cmp){
				++C;
				for(auto p : v){
					cgraph[C].push_back(p.second);
					cgraph[C].push_back(p.first);
				}
				sort(cgraph[C].begin(), cgraph[C].end());
				cgraph[C].erase(unique(cgraph[C].begin(), cgraph[C].end()), cgraph[C].end());
				for(int n : cgraph[C]){
					cgraph[n].push_back(C);
				}
			}
			dfs2(i);
		}
	}
	cout << 2*ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 102 ms 31412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7680 KB Output is correct
2 Correct 10 ms 7680 KB Output is correct
3 Correct 9 ms 7552 KB Output is correct
4 Correct 9 ms 7680 KB Output is correct
5 Correct 10 ms 7680 KB Output is correct
6 Correct 9 ms 7680 KB Output is correct
7 Correct 10 ms 7680 KB Output is correct
8 Correct 9 ms 7680 KB Output is correct
9 Correct 9 ms 7680 KB Output is correct
10 Correct 10 ms 7680 KB Output is correct
11 Correct 13 ms 7680 KB Output is correct
12 Correct 10 ms 7808 KB Output is correct
13 Correct 10 ms 7936 KB Output is correct
14 Correct 21 ms 10880 KB Output is correct
15 Correct 31 ms 13696 KB Output is correct
16 Correct 41 ms 16212 KB Output is correct
17 Correct 11 ms 7552 KB Output is correct
18 Correct 9 ms 7552 KB Output is correct
19 Correct 9 ms 7552 KB Output is correct
20 Correct 9 ms 7680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 139 ms 52516 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7552 KB Output is correct
2 Correct 9 ms 7552 KB Output is correct
3 Incorrect 9 ms 7552 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 151 ms 52620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -