Submission #925210

# Submission time Handle Problem Language Result Execution time Memory
925210 2024-02-11T03:21:26 Z pan Firefighting (NOI20_firefighting) C++17
3 / 100
267 ms 34888 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include "bits_stdc++.h"
#include <stdio.h>
#include <algorithm>
#include <memory.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
using namespace std;
//using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
ll const INF = 1e13;
ll n, k, x, y, z;
vector<pi> adj[300005];
vector<ll> ans;
pi dfs(ll p, ll from, ll dist)
{
	ll overflow = -INF, underflow = 0;
	for (pi u: adj[from])
	{
		if (u.f==p) continue;
		pi ret = dfs(from, u.f, u.s);
		if (ret.f==0) underflow = max(underflow, ret.s);
		if (ret.f==1) overflow = max(overflow, ret.s);
	}
	pi ret;
	if (overflow>=underflow) {ret = mp(1, overflow - dist);}
	else
	{
		if (underflow+dist>k)
		{
			ans.pb(from);
			ret = mp(1, k-dist);
		}
		else
		{
			ret = mp(0, underflow + dist);
		}
	}
	if (ret.f && ret.s<=0) ret= mp(0, 0); // reset from overflow to underflow
	//show2(ret.f, ret.s);
	return ret;
	
}
int main()
{
	input(n); input(k);
	for (ll i=0; i<n-1; ++i)
	{
		input(x); input(y); input(z);
		adj[x].pb(mp(y,z));
		adj[y].pb(mp(x,z));
	}
	dfs(-1, 1, INF);
	print((ll) ans.size(), '\n');
	for (ll u: ans) print(u, ' ');
	return 0;
}

Compilation message

Firefighting.cpp: In function 'int main()':
Firefighting.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
Firefighting.cpp:65:2: note: in expansion of macro 'input'
   65 |  input(n); input(k);
      |  ^~~~~
Firefighting.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
Firefighting.cpp:65:12: note: in expansion of macro 'input'
   65 |  input(n); input(k);
      |            ^~~~~
Firefighting.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
Firefighting.cpp:68:3: note: in expansion of macro 'input'
   68 |   input(x); input(y); input(z);
      |   ^~~~~
Firefighting.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
Firefighting.cpp:68:13: note: in expansion of macro 'input'
   68 |   input(x); input(y); input(z);
      |             ^~~~~
Firefighting.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
Firefighting.cpp:68:23: note: in expansion of macro 'input'
   68 |   input(x); input(y); input(z);
      |                       ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 209 ms 34744 KB Output is correct
2 Correct 236 ms 34740 KB Output is correct
3 Correct 86 ms 17500 KB Output is correct
4 Correct 197 ms 34888 KB Output is correct
5 Correct 3 ms 7256 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 2 ms 7276 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Incorrect 2 ms 7260 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Incorrect 2 ms 7272 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 267 ms 34880 KB Output is correct
2 Incorrect 85 ms 20264 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Incorrect 2 ms 7516 KB Integer parameter [name=F] equals to 0, violates the range [1, 1199]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 175 ms 29528 KB Output is correct
2 Correct 150 ms 28316 KB Output is correct
3 Incorrect 213 ms 30036 KB Integer parameter [name=F] equals to 0, violates the range [1, 298259]
4 Halted 0 ms 0 KB -