답안 #392503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392503 2021-04-21T09:03:29 Z patrikpavic2 관광지 (IZhO14_shymbulak) C++17
50 / 100
51 ms 22876 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>
#include <cstdlib>

#define X first
#define Y second
#define PB push_back

using namespace std;

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

const int N = 2e5 + 500;
const int OFF = (1 << 18);

pil add(pil A, pil B){
	return {max(A.X, B.X), A.Y * (A.X >= B.X) + B.Y * (B.X >= A.X)};
}

pil mul(pil A, pil B){
	return {A.X + B.X, A.Y * B.Y};
}

int un[N], n;
vector < int > v[N];
vector < int > cik;
pil sol = {0, 0};
pil ja[N];

pil f(int x, int lst){
	pil dep = {0, 1};
	for(int y : v[x]){
		if(y == lst || un[y]) continue;
		pil nxt = f(y, x);
		sol = add(sol, mul(dep, nxt));
		dep = add(dep, nxt);
	}
	dep.X++;
	return dep;
}

int bio[N];
stack < int > S;

void dfs(int x, int lst){
	if((int)cik.size() != 0) return;
	if(bio[x]){
		cik.PB(x);
		while(S.top() != x)
			cik.PB(S.top()), S.pop();
		return;			
	}
	bio[x] = 1;
	S.push(x);
	for(int y : v[x])
		if(y != lst)
			dfs(y, x);
	S.pop();
}


int main(){
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		int x, y; scanf("%d%d", &x, &y);
		v[x].PB(y), v[y].PB(x);
	}
	dfs(1, 1);
	for(int x : cik) un[x] = 1;
	for(int i = 0;i < (int)cik.size();i++)
		ja[i] = f(cik[i], cik[i]), ja[i].X--;
	int m = (int)cik.size();
	for(int i = 0;i < m;i++){
		for(int j = i + 1;j < m;j++){
			pil kof = {min(abs(i - j), m - abs(i - j)), 1 + (2 * abs(i - j) == m)};
			sol = add(sol, mul(mul(ja[i], ja[j]), kof));
		}
	}
	printf("%lld\n", sol.Y);
	return 0;
}





Compilation message

shymbulak.cpp: In function 'int main()':
shymbulak.cpp:66:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
shymbulak.cpp:68:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   68 |   int x, y; scanf("%d%d", &x, &y);
      |             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 5012 KB Output is correct
5 Correct 3 ms 5016 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4944 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 5024 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 5012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5068 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 5068 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 4 ms 5196 KB Output is correct
6 Correct 5 ms 5196 KB Output is correct
7 Correct 5 ms 5196 KB Output is correct
8 Correct 5 ms 5196 KB Output is correct
9 Correct 5 ms 5196 KB Output is correct
10 Correct 5 ms 5196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 8256 KB Output is correct
2 Correct 51 ms 8708 KB Output is correct
3 Runtime error 49 ms 22876 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -