Submission #49391

# Submission time Handle Problem Language Result Execution time Memory
49391 2018-05-28T09:04:20 Z hamzqq9 Toll (APIO13_toll) C++14
16 / 100
4 ms 544 KB
#include<bits/stdc++.h>
#define lf double
#define ll long long
#define cc pair<char,char>
#define ull unsigned ll
#define ii pair<int,int>
#define li pair<ll,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define iiii2 pair<int,iii>
#define lii pair<ll,ii>
#define lolo pair<ll,ll>
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000000
#define inf 1000000000
#define N 5005
#define LOG 20
#define magic 100
#define KOK 250
#define EPS 0.0025
#define pw(x) (1<<(x))
#define PI 3.1415926535
using namespace std;

#define iii2 pair< ii,int>

int n,m,k,x,y,z,tot;
int ar[30];
ii a[N];
iii e[N];
ll sub[N];
int ata[N],p[N];
bool ok[N];
vector<iii2> v[N];
ll ans,top;

void dfs(int node,int ata) {

	sub[node]=p[node];

	for(iii2 to:v[node]) {

		if(to.st.st==ata) continue ;

		dfs(to.st.st,node);

		sub[node]+=sub[to.st.st];

		if(to.nd) top+=1ll*to.st.nd*sub[to.st.st];

	}

}

int bul(int node) {

	if(ata[node]==node) return node;

	return ata[node]=bul(ata[node]);

}

void build() {

	for(int i=1;i<=n;i++) ata[i]=i;

	for(int i=1;i<=tot;i++) ok[i]=0;

	for(int i=1;i<=n;i++) v[i].clear();

	for(int i=1;i<=m;i++) {

		int n1=e[i].nd.st;
		int n2=e[i].nd.nd;

		int r1=bul(n1);
		int r2=bul(n2);

		if(r1==r2) continue ;

		int bug=0;
		int tut=0;
		int ok2;

		for(int i=1;i<=tot;i++) {

			if(ok[i]) continue ;

			int rr1=bul(a[ar[i]].st);
			int rr2=bul(a[ar[i]].nd);

			if((rr1==r1 && rr2==r2) || ((rr1==r2 && rr2==r1))) {

				bug++;
				tut=ar[i];
				ok2=i;

			}

		}

		if(bug>1) return ;

		ata[r1]=r2;

		if(bug==1) {

			ok[ok2]=1;

			v[a[tut].st].pb({{a[tut].nd,e[i].st},1});
			v[a[tut].nd].pb({{a[tut].st,e[i].st},1});

		}
		else {

			v[n1].pb({{n2,e[i].st},0});
			v[n2].pb({{n1,e[i].st},0});

		}

	}

	dfs(1,0);

	ans=max(ans,top);

}
 
int main() {
 
//	freopen("input.txt","r",stdin);
 
	scanf("%d %d %d",&n,&m,&k);

	for(int i=1;i<=m;i++) {

		scanf("%d %d %d",&x,&y,&z);

		e[i]={z,{x,y}};

	}

	for(int i=0;i<k;i++) {

		scanf("%d %d",&x,&y);

		a[i]={x,y};

	}

	sort(e+1,e+1+m);

	for(int i=1;i<=n;i++) {

		scanf("%d",&p[i]);

	}

	for(int i=0;i<pw(k);i++) {

		tot=0;
		top=0;

		for(int num=i;num>0;num-=(num&-num)) {

			int no=(num&-num);

			ar[++tot]=log2(no);

		}

		build();

	}
 
	printf("%lld",ans);

}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:148:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
toll.cpp:152:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&x,&y,&z);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
toll.cpp:160:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&x,&y);
   ~~~~~^~~~~~~~~~~~~~~
toll.cpp:170:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&p[i]);
   ~~~~~^~~~~~~~~~~~
toll.cpp: In function 'void build()':
toll.cpp:123:11: warning: 'ok2' may be used uninitialized in this function [-Wmaybe-uninitialized]
    ok[ok2]=1;
    ~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Incorrect 4 ms 544 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Incorrect 4 ms 544 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Incorrect 4 ms 544 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Incorrect 4 ms 544 KB Output isn't correct
4 Halted 0 ms 0 KB -