QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#120553#4357. School Roadlmeowdn0 5ms20592kbC++143.0kb2023-07-06 21:24:352023-07-06 21:24:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 21:24:38]
  • 评测
  • 测评结果:0
  • 用时:5ms
  • 内存:20592kb
  • [2023-07-06 21:24:35]
  • 提交

answer

#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<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
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=2e5+5;
int n,m,deg[N],del[N],w[N],low[N],dfn[N],tick,in[N],st[N],top;
map<pii,int>ed;
vp e[N],t[N];
queue<int>q;

void dfs(int u,int fa) {
  dfn[u]=low[u]=++tick, in[u]=1, st[++top]=u;
  for(auto [v,id]:e[u]) if(id!=fa) {
    if(!dfn[v]) {
      dfs(v,fa), chmin(low[u],low[v]);
      if(low[v]>=dfn[u]) {
        vi res={u}; bool flag=0; do {
          int x=st[top]; res.eb(x), in[x]=0, flag|=(x==n);
        } while(st[top--]!=v);
        if(flag) for(int x:res) del[x]=1;
      }
    } else if(in[v]) chmin(low[u],dfn[v]);
  }
}

bool work() {
  rep(u,1,n) {
    for(auto [v,w]:e[u]) if(u<v) {
      if(!ed.count(pii(u,v))) ed[pii(u,v)]=w;
      else if(ed[pii(u,v)]!=w) return 0;
      else --deg[u], --deg[v];
    }
  }
  rep(i,1,n) if(deg[i]==2) q.push(i);
  while(!q.empty()) {
    int u=q.front(); q.pop();
    if(del[u]||u==1||u==n) continue; assert(deg[u]==2);
    int x=0,wx=0,y=0,wy=0;
    for(auto [v,w]:e[u]) if(!del[v]) {
      if(!x) x=v, wx=w;
      else y=v, wy=w;
    }
    assert(x), assert(y), del[u]=1;
    if(x>y) swap(x,y);
    if(!ed.count(pii(x,y))) ed[pii(x,y)]=wx+wy;
    else if(ed[pii(x,y)]!=wx+wy) return 1;
    else {
      --deg[x]; if(deg[x]==2&&x!=1) q.push(x);
      --deg[y]; if(deg[y]==2&&y!=1) q.push(y);
    }
  }
  rep(i,2,n-1) if(!del[i]) return 1;
  return 0;
}

signed main() {
  n=read(), m=read();
  rep(i,1,m) {
    int u=read(), v=read(); w[i]=read();
    e[u].eb(v,i);
    e[v].eb(u,i);
  }
  e[1].eb(n,m+1), e[n].eb(1,m+1);
  dfs(1,0);
  rep(i,1,n) del[i]^=1;
  rep(u,1,n) if(!del[u])
    for(auto [v,id]:e[u]) if(!del[v])
      if(w[id]) t[u].eb(v,w[id]), deg[u]++;
  rep(u,1,n) e[u]=t[u];
  printf("%d\n",work());
  return 0;
}

詳細信息

Subtask #1:

score: 0
Dangerous Syscalls

Test #1:

score: 7
Accepted
time: 3ms
memory: 20592kb

input:

14 40
8 12 570429827
6 10 592780730
13 14 299807355
4 10 729771483
4 10 729771483
6 9 746405411
2 3 696576351
12 14 192640790
4 13 284900209
1 2 857968292
12 14 192640790
8 12 570429827
6 10 592780730
6 9 746405411
9 11 329648726
4 13 284900209
2 3 696576351
4 10 729771483
5 11 101819611
3 7 1824073...

output:

0

result:

ok single line: '0'

Test #2:

score: -7
Dangerous Syscalls

input:

41 40
12 19 102666211
30 32 10931929
8 34 88862177
11 29 37284876
6 35 24117284
6 11 24483138
10 35 11019124
4 22 509961847
20 39 77098829
25 33 563195350
22 24 781289886
2 17 238185039
21 27 288940653
3 31 62767763
18 21 350694322
2 40 228181439
3 33 109276182
31 36 203571934
28 34 64098677
14 24 3...

output:


result:


Subtask #2:

score: 0
Dangerous Syscalls

Test #11:

score: 0
Dangerous Syscalls

input:

18 40
3 10 26965732
5 15 67047331
3 17 42474964
13 15 129212204
9 18 142540287
2 14 27157962
5 15 67047331
5 15 67047331
5 15 67047331
4 16 212978971
6 12 51548223
4 18 192438222
13 16 60052417
16 17 162364835
6 17 55527270
9 11 58810843
3 7 95393586
13 15 129212204
2 17 67824762
5 15 67047331
15 16...

output:


result:


Subtask #3:

score: 0
Dangerous Syscalls

Test #18:

score: 0
Dangerous Syscalls

input:

100000 99999
42115 93495 19881095
21969 68351 161710
7405 86343 27129
37307 45676 320013
30388 71545 117761
22026 68957 65332
77949 81644 2281387
24865 95079 341488
9849 98496 2548159
53911 79572 4962105
24880 62622 1678564
15943 22168 1524688
67424 78323 2450655
32175 74893 1908332
35640 39305 1043...

output:


result:


Subtask #4:

score: 0
Wrong Answer

Test #57:

score: 0
Wrong Answer
time: 5ms
memory: 20420kb

input:

18 400
11 18 145314505
1 18 242896789
1 18 242896789
5 13 31030812
13 18 93451080
1 18 242896789
1 7 123378068
1 18 242896789
1 18 242896789
1 18 242896789
1 18 242896789
1 18 242896789
1 18 242896789
1 3 42183985
1 18 242896789
13 18 93451080
1 18 242896789
13 18 93451080
1 18 242896789
1 18 242896...

output:

1

result:

wrong answer 1st lines differ - expected: '0', found: '1'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%