Submission #44074910


Source Code Expand

// Problem: G - Avoid Straight Line
// Contest: AtCoder - UNIQUE VISION Programming Contest 2023 Summer(AtCoder Beginner Contest 312)
// URL: https://atcoder.jp/contests/abc312/tasks/abc312_g
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define rep1(i, l, r) for (int i = l; i <= int(r); ++i)
#define rep2(i, l, r) for (int i = l; i >= int(r); --i)
#define cop(i, l, r, a, b) rep1(i, l, r) a[i] = b[i]
#define rep(i, x) for (int i = pnt[x]; i; i = nxt[i])
#define rer(i, l, r, a) rep1(i, l, r) read(a[i])
#define ptc putchar
#define il inline
#define eb emplace_back
#define ef emplace_front
#define mp make_pair
#define fst first
#define snd second
#define sqr(x) ((x) * (x))
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define YES ptc('Y'), ptc('E'), ptc('S'), ptc('\n')
#define Yes ptc('Y'), ptc('e'), ptc('s'), ptc('\n')
#define NO ptc('N'), ptc('O'), ptc('\n')
#define No ptc('N'), ptc('o'), ptc('\n')
#define rout return 0
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// typedef __int128 bll;
// typedef unsigned __int128 ubll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e5 + 10, inf = ~0U >> 2, INF = ~0U >> 1;
const int LOGN = log2(MAXN) + 1;
const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
namespace stupid_lrc {
	template <typename T> il bool read(T &x) {
		x = 0; bool f = false; char ch;
		while (!isdigit(ch = getchar())) {
			f ^= !(ch ^ '-');
			if (ch == EOF) return false;
		}
		while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch & 15), ch = getchar();
		if (f) x = ~x + 1; return true;
	}
	il int read() {int x; read(x); return x;}

	template <typename T> il bool read(pair <T, T> &x) {return read(x.fst) && read(x.snd);}

	template <typename T, typename ...L>
	il bool read(T &x, L &...y) {return read(x) && read(y...);}

	template <typename T> il T lowbit(const T &x) {return x & -x;}
}
using namespace stupid_lrc;
int n, siz[MAXN], d[MAXN]; ll ans, p;
vector <int> lnk[MAXN];

il void add(const int &x, const int &y) {
	lnk[x].eb(y); lnk[y].eb(x);
}

il void dfs(int x, int p) {
	siz[x] = 1; d[x] = d[p] + 1;
	for (auto v : lnk[x]) if (v ^ p) dfs(v, x), siz[x] += siz[v];
}

int main() {
	read(n); ans = 1ll * n * (n - 1) * (n - 2) / 6;
	rep1(i, 2, n) add(read(), read());
	dfs(1, 0);
	rep1(i, 1, n) for (auto t : lnk[i]) {
		int s = d[i] > d[t] ? siz[i] : siz[t];
		p += 1ll * s * (n - s);
	} p >>= 1;
	ans -= p; ans += 1ll * n * (n - 1) / 2;
	printf("%lld", ans);
	rout;
}
 

Submission Info

Submission Time
Task G - Avoid Straight Line
User liangruichen
Language C++ (GCC 9.2.1)
Score 550
Code Size 2626 Byte
Status AC
Exec Time 103 ms
Memory 27540 KiB

Compile Error

./Main.cpp: In function ‘bool stupid_lrc::read(T&)’:
./Main.cpp:48:3: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
   48 |   if (f) x = ~x + 1; return true;
      |   ^~
./Main.cpp:48:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
   48 |   if (f) x = ~x + 1; return true;
      |                      ^~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 550 / 550
Status
AC × 3
AC × 40
Set Name Test Cases
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt
Case Name Status Exec Time Memory
sample00.txt AC 12 ms 8256 KiB
sample01.txt AC 9 ms 8236 KiB
sample02.txt AC 10 ms 8176 KiB
testcase00.txt AC 8 ms 8276 KiB
testcase01.txt AC 10 ms 8156 KiB
testcase02.txt AC 8 ms 8100 KiB
testcase03.txt AC 66 ms 20260 KiB
testcase04.txt AC 100 ms 24272 KiB
testcase05.txt AC 77 ms 20204 KiB
testcase06.txt AC 103 ms 27540 KiB
testcase07.txt AC 36 ms 13072 KiB
testcase08.txt AC 58 ms 16384 KiB
testcase09.txt AC 47 ms 13940 KiB
testcase10.txt AC 60 ms 16344 KiB
testcase11.txt AC 45 ms 12980 KiB
testcase12.txt AC 80 ms 15840 KiB
testcase13.txt AC 64 ms 14308 KiB
testcase14.txt AC 89 ms 16132 KiB
testcase15.txt AC 46 ms 13688 KiB
testcase16.txt AC 73 ms 16128 KiB
testcase17.txt AC 47 ms 12852 KiB
testcase18.txt AC 86 ms 16096 KiB
testcase19.txt AC 51 ms 14732 KiB
testcase20.txt AC 72 ms 17112 KiB
testcase21.txt AC 39 ms 13292 KiB
testcase22.txt AC 71 ms 16776 KiB
testcase23.txt AC 56 ms 16780 KiB
testcase24.txt AC 91 ms 22584 KiB
testcase25.txt AC 62 ms 19740 KiB
testcase26.txt AC 86 ms 19860 KiB
testcase27.txt AC 69 ms 14820 KiB
testcase28.txt AC 92 ms 16424 KiB
testcase29.txt AC 52 ms 13252 KiB
testcase30.txt AC 93 ms 16200 KiB
testcase31.txt AC 52 ms 12896 KiB
testcase32.txt AC 85 ms 16256 KiB
testcase33.txt AC 87 ms 16048 KiB
testcase34.txt AC 80 ms 16352 KiB
testcase35.txt AC 77 ms 15568 KiB
testcase36.txt AC 86 ms 16424 KiB