Submission #155692

# Submission time Handle Problem Language Result Execution time Memory
155692 2019-09-29T23:00:48 Z TadijaSebez Telegraph (JOI16_telegraph) C++11
0 / 100
4 ms 2684 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=100050;
vector<pair<int,int>> E[N];
int a[N],c[N],go[N];
bool was[N];
int main()
{
	int n;
	scanf("%i",&n);
	ll sum=0,ans=0;
	for(int i=1;i<=n;i++) scanf("%i %i",&a[i],&c[i]),E[a[i]].pb({c[i],i}),sum+=c[i];
	for(int i=1;i<=n;i++)
	{
		sort(E[i].rbegin(),E[i].rend());
		if(E[i].size()) go[E[i][0].second]=i,ans+=E[i][0].first;
	}
	bool cyc=0;
	for(int i=1;i<=n;i++) if(!was[i])
	{
		int mx=-2e9,j,cnt=0;
        for(j=i;j && !was[j];j=go[j])
		{
			int tmp=E[j].size()?-E[j][0].first:0;
			if(E[j].size()>=2) tmp+=E[j][1].first;
			mx=max(mx,tmp);
			was[j]=1;cnt++;
		}
		if(j) ans+=mx;if(j && cnt==n) cyc=1;
	}
	if(cyc) printf("0\n");
	else printf("%lld\n",sum-ans);
	return 0;
}

Compilation message

telegraph.cpp: In function 'int main()':
telegraph.cpp:31:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   if(j) ans+=mx;if(j && cnt==n) cyc=1;
   ^~
telegraph.cpp:31:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   if(j) ans+=mx;if(j && cnt==n) cyc=1;
                 ^~
telegraph.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
telegraph.cpp:14:71: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%i %i",&a[i],&c[i]),E[a[i]].pb({c[i],i}),sum+=c[i];
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2684 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Incorrect 4 ms 2680 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2684 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Incorrect 4 ms 2680 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2684 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Incorrect 4 ms 2680 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2684 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Incorrect 4 ms 2680 KB Output isn't correct
4 Halted 0 ms 0 KB -