結果

問題 No.1038 TreeAddQuery
ユーザー nullnull
提出日時 2020-04-24 22:51:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 3,545 bytes
コンパイル時間 1,549 ms
コンパイル使用メモリ 143,076 KB
最終ジャッジ日時 2025-01-10 00:22:29
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other WA * 5 MLE * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:129:26: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type’ {aka ‘long long int’} [-Wformat=]
  129 |                 printf("%d\n", ans[--x]);
      |                         ~^
      |                          |
      |                          int
      |                         %lld
main.cpp: In function ‘void scans(std::string&)’:
main.cpp:78:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   78 |         scanf("%c", &c);
      |         ~~~~~^~~~~~~~~~
main.cpp:79:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   79 |         if (c == '\n')scanf("%c", &c);
      |                       ~~~~~^~~~~~~~~~
main.cpp:82:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   82 |                 scanf("%c", &c);
      |                 ~~~~~^~~~~~~~~~
main.cpp: In function ‘void scanc(char&)’:
main.cpp:88:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   88 |         scanf("%c", &c);
      |         ~~~~~^~~~~~~~~~
main.cpp:91:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   91 |                 scanf("%c", &c);
      |                 ~~~~~^~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:114:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  114 |         scanf("%d%d", &n, &q);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:118:22: warning: 

ソースコード

diff #

/*
このコード、と~おれ!
Be accepted!
∧_∧ 
(。・ω・。)つ━☆・*。
⊂   ノ    ・゜+.
 しーJ   °。+ *´¨)
          .· ´¸.·*´¨) ¸.·*¨)
		            (¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/

void dfs(const vector<vector<int>>& tree, vector<vector<vector<int>>>& a, const int& now, const int& bef, const int& cnt, const int& root) {
	a[root][cnt].emplace_back(now);
	for (const auto& aa : tree[now]) {
		if (aa != bef)dfs(tree, a, aa, now, cnt + 1, root);
	}
}

int main() {

	int n, q;
	scanf("%d%d", &n, &q);
	vector<vector<int>> tree(n);
	int a, b;
	rep(i, n - 1) {
		scanf("%d%d", &a, &b);
		--a; --b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	vector<vector<vector<int>>> p(n, vector<vector<int>>(n));
	rep(i, n) dfs(tree, p, i, -1, 0, i);
	vector<ll> ans(n);
	int x, y, z;
	rep(i, q) {
		scanf("%d%d%d", &x, &y, &z);
		printf("%d\n", ans[--x]);
		for (int j = 0; j <= y; ++j) {
			for (const auto& aa : p[x][j]) {
				ans[aa] += z;
			}
		}
	}

	Please AC;
}
0