比赛 东方版NOIP模拟赛 评测结果 AAATTTTAATAAAATATTTT
题目名称 Yuyuko 最终得分 50
用户昵称 Satoshi 运行时间 32.257 s
代码语言 C++ 内存使用 12.18 MiB
提交时间 2015-10-28 21:12:08
显示代码纯文本
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
const int maxn = 3*1e4 + 10;
const int maxm = 10e5 + 10;
int head[maxn], tot = 0, n, m, ans = INF;
int next[maxm], v[maxm], w[maxm];
bool vis[maxm], ok = false, vised = 0;
void add(int a, int b, int c){
  v[++tot] = b; w[tot] = c;
  next[tot] = head[a];
  head[a] = tot;
}
void dfs(int u, int ww){
  if(u == 1 && vised){
    ok = true; 
    if(ww < ans) ans = ww;
    return;
  }
  if(u == 1) vised = 1;
  for(int i = head[u]; i; i = next[i])
    if(!vis[i]){
      vis[i] = true;
      int ano = i & 1 ? i + 1 : i - 1;
      vis[ano] = true;
      dfs(v[i], ww + w[i]);
      vis[i] = false;
      vis[ano] = false;
    }
}
int main()
{
  freopen("zaw.in", "r", stdin);
  freopen("zaw.out", "w", stdout);
  cin >> n >> m;
  int a, b, c, d;
  for(int i = 0; i < m; i++){
    scanf("%d%d%d%d", &a, &b, &c, &d);
    add(a, b, c);
    add(b, a, d);
  }
  memset(vis, false, sizeof(vis));
  dfs(1, 0);
  if(ok) cout << ans << endl;
  else cout << -1 << endl;
  return 0;
}