QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#429817#8136. Rebellious EdgelmeowdnWA 0ms20264kbC++141.9kb2024-06-02 21:40:372024-06-02 21:40:38

Judging History

你现在查看的是最新测评结果

  • [2024-06-02 21:40:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:20264kb
  • [2024-06-02 21:40:37]
  • 提交

answer

//Shirasu Azusa 2024.6
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;  
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} 
  return x*w;
}

const int N=5e5+5,inf=0x3f3f3f3f3f3f3f3f;
int n,m,g[N],ans,sp,vst[N],id[N],f[N];
struct ed {int u,v,w;} e[N];
vi p[N];

void work() {
  n=read(), m=read();
  rep(i,1,n) p[i].clear(), f[i]=0;
  rep(i,1,m) {
    e[i].u=read(), e[i].v=read(), e[i].w=read();
    if(e[i].u>e[i].v) sp=i; p[e[i].u].eb(i);
  }
  ans=0;
  rep(i,1,n) g[i]=0; e[0].w=inf;
  rep(i,1,m) {
    if(e[g[e[i].v]].w>e[i].w) {
      g[e[i].v]=i;
    }
  }
  bool flag=0;
  rep(i,1,n) if(g[i]) ans+=e[g[i]].w;
  rep(i,1,n) flag|=(g[i]==sp);
  if(flag) {
    rep(i,2,n) f[i]=inf;
    rep(i,1,n) {
      for(int j:p[i]) chmin(f[e[j].v],f[i]+e[j].w-e[g[e[j].v]].w);
    }
  }
  printf("%lld\n",ans+f[e[sp].u]);
}

signed main() {
  int T=read(); while(T--) work();
  return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 20264kb

input:

3
5 6
1 2 4
1 3 2
2 3 0
3 4 1
4 5 1
5 2 1
4 4
1 2 4
1 3 6
1 4 8
4 2 1000000
3 3
1 2 100
2 1 10
2 3 1000

output:

5
18
1110

result:

wrong answer 3rd numbers differ - expected: '1100', found: '1110'