QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#462303#7177. Many Many CyclesAlishWA 1ms7928kbC++171.7kb2024-07-03 17:15:222024-07-03 17:15:23

Judging History

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

  • [2024-07-03 17:15:23]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7928kb
  • [2024-07-03 17:15:22]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long int	ll;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;


#define F		        first
#define S		        second
#define pb		        push_back
#define endl            '\n'
#define Mp              make_pair
#define all(x)          x.begin(), x.end()
#define debug(x)        cerr << #x << " = " << x << endl;
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("tests.in" , "r" , stdin) ;

ll mod = 1e9+7;

const int N = 5e3+23;

vector<pll> g[N];
int h[N], vis[N];
int LCA[N][N];
ll d[N];
vector<pii> be;
vector<int> sub[N];
int n, m;
ll ans=0;

void dfs(int v){
    vis[v]=1;
    sub[v].pb(v);
    LCA[v][v]=v;
    for (auto pp: g[v]){
        int u=pp.F, w=pp.S;
        if(!vis[u]){
            h[u]=h[v]+1;
            d[u]=d[v]+w;
            dfs(u);
            for (int vp: sub[v]) for (int up: sub[u]) LCA[up][vp]=LCA[vp][up]=v;
            for (int up: sub[u]) sub[v].pb(up);
            sub[u].clear();
        }
        else if(h[v]<h[u]){
            be.pb({v, u});
            ans=__gcd(ans, w+d[u]-d[v]);

        }
    }
}

int main()
{

    cin>>n>>m;
    for (int i=0; i<m; i++){
        int v, u, w; cin>>v>>u>>w;
        g[v].pb({u, w}); g[u].pb({v, w});
    }
    for (int v=1; v<=n; v++) if(!vis[v]){
        be.clear();
        dfs(v);
        for (int i=0; i<be.size(); i++) for (int j=i+1; j<be.size(); j++){
            pii a=be[i], b=be[j];
            int v=LCA[a.S][b.S];
            int u=a.F;
            if(d[u]>d[b.F]) u=b.F;
            if(d[v]-d[u]>0) ans=__gcd(ans, 2*(d[v]-d[u]));

        }
    }
    cout<<ans<<endl;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3900kb

input:

4 4
1 2 1
2 3 1
3 4 1
4 1 1

output:

4

result:

ok answer is '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

4 5
1 2 1
1 3 2
1 4 1
2 3 1
3 4 1

output:

4

result:

ok answer is '4'

Test #3:

score: 0
Accepted
time: 0ms
memory: 5840kb

input:

20 50
1 2 8
1 3 1
3 4 5
3 5 9
3 6 5
6 7 6
7 8 8
2 9 2
8 10 3
8 11 7
8 12 5
3 13 4
7 14 3
6 15 7
9 16 6
8 17 7
16 18 9
16 19 3
18 20 10
11 3 2
17 1 1
16 2 2
15 1 1
10 3 2
9 1 2
19 2 1
6 1 2
7 3 1
17 3 2
15 3 2
8 6 2
5 1 2
8 1 2
12 1 1
12 7 1
4 1 2
18 2 1
11 7 1
14 1 1
18 1 1
18 9 1
10 6 1
14 3 2
20 2...

output:

2

result:

ok answer is '2'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3972kb

input:

20 50
1 2 18468
1 3 26501
3 4 15725
3 5 29359
3 6 24465
6 7 28146
7 8 16828
2 9 492
8 10 11943
8 11 5437
8 12 14605
3 13 154
7 14 12383
6 15 18717
9 16 19896
8 17 21727
16 18 11539
16 19 19913
18 20 26300
11 3 2
17 1 1
16 2 2
15 1 1
10 3 2
9 1 2
19 2 1
6 1 2
7 3 1
17 3 2
15 3 2
8 6 2
5 1 2
8 1 2
12 ...

output:

1

result:

ok answer is '1'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 7928kb

input:

100 150
1 2 184676335
1 3 191705725
1 4 293606963
1 5 57078146
2 6 168279962
6 7 29961943
5 8 54392392
5 9 39020154
5 10 123837422
7 11 197199896
3 12 217274772
7 13 18709913
6 14 263007036
11 15 287053812
3 16 303347674
9 17 151417712
17 18 68705548
15 19 326652758
12 20 128598724
2 21 275290779
11...

output:

1

result:

wrong answer expected '3', found '1'