답안 #49388

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49388 2018-05-28T08:57:30 Z hamzqq9 통행료 (APIO13_toll) C++14
0 / 100
3 ms 760 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;

		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) {

				bug++;
				tut=ar[i];

			}

		}

		if(bug>1) return ;

		ata[r1]=r2;

		if(bug==1) {

			ok[tut]=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:144:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("input.txt","r",stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:146: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:150: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:158: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:168:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&p[i]);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -