比赛 东方版NOIP模拟赛 评测结果 AAATTTTATTAAAAEEEEEE
题目名称 Yuyuko 最终得分 40
用户昵称 Kirito 运行时间 20.856 s
代码语言 C++ 内存使用 95.79 MiB
提交时间 2015-10-28 20:45:08
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
struct cnm
{
	int next;
	int next_v;
}wrnm;
vector<cnm>p[10000];
int ans=0x7fffffff;
bool nico[10000][10000];
void cao(int mark,int x,int sum)
{
	int i,next,next_v;
	if(x==1&&mark!=0)
	{
		if(ans>sum)ans=sum;
		return ;
	}
	for(i=0;i<p[x].size();i++)
	{
		next=p[x][i].next;
		next_v=p[x][i].next_v;
		if(!nico[x][next]&&!nico[next][x])
		{
			nico[x][next]=1;
			nico[next][x]=1;
			cao(x,next,sum+next_v);
			nico[x][next]=0;
			nico[next][x]=0;
		}
	}
}
int main()
{
	freopen("zaw.in","r",stdin);
	freopen("zaw.out","w",stdout);
	int n,m,x,y,v1,v2,i;
	scanf("%d %d",&n,&m);
	for(i=1;i<=m;i++)
	{
		scanf("%d %d %d %d",&x,&y,&v1,&v2);
		wrnm.next=y;
		wrnm.next_v=v1;
		p[x].push_back(wrnm);
		wrnm.next=x;
		wrnm.next_v=v2;
		p[y].push_back(wrnm);
	}
	cao(0,1,0);
	if(ans==0x7fffffff){printf("-1");return 0;}
	printf("%d",ans);
	return 0;
}